From 6a7cc212a70393fd96305ff1441d114ba94cd826 Mon Sep 17 00:00:00 2001 From: Clint Adams Date: Wed, 22 Apr 2015 14:59:47 -0400 Subject: commit amex sanitation scripts --- sort-and-sanitize-the-other-kind-of-amex-export.hs | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 sort-and-sanitize-the-other-kind-of-amex-export.hs (limited to 'sort-and-sanitize-the-other-kind-of-amex-export.hs') diff --git a/sort-and-sanitize-the-other-kind-of-amex-export.hs b/sort-and-sanitize-the-other-kind-of-amex-export.hs new file mode 100644 index 0000000..adeac06 --- /dev/null +++ b/sort-and-sanitize-the-other-kind-of-amex-export.hs @@ -0,0 +1,30 @@ +import Text.CSV +import Text.Printf (printf) + +import Data.List (sort, isPrefixOf, groupBy) + +import System.Environment (getArgs) + +normAndInvertAmount :: Field -> Field +normAndInvertAmount amt | amt == "" = "" + | otherwise = printf "%.2f" (0 - (read amt :: Double)) + +compressWhitespace :: String -> String +compressWhitespace x = map head $ groupSpaces x + where groupSpaces "" = [""] + groupSpaces x = groupBy (\x y -> x==' ' && y==' ') x + +massageAmount :: [Field] -> [Field] +massageAmount [a,b,c,d,e,f,g,h,i,j] = [a,b,c,d,compressWhitespace e,f,g,h,i,normAndInvertAmount j] +-- massageAmount [a,b,c,d,e,f,g,h] = [a,b,compressWhitespace c,d,e,f,g,normAndInvertAmount h] +massageAmount xs = xs + +sanitySort :: [Record] -> [Record] +sanitySort ts = map (massageAmount) (sort ts) + +main = do + args <- getArgs + result <- parseCSVFromFile (head args) + case result of + Left e -> putStrLn ("Parse fail: " ++ show e) + Right ts -> putStrLn $ printCSV (sanitySort ts) -- cgit v1.2.3