summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClint Adams <clint@softwarefreedom.org>2015-04-22 14:59:47 -0400
committerClint Adams <clint@softwarefreedom.org>2015-04-22 14:59:47 -0400
commit6a7cc212a70393fd96305ff1441d114ba94cd826 (patch)
tree8e30b64b378cdc3eb4f2440147dd332be06fe4fc
commit amex sanitation scripts
-rw-r--r--sort-and-sanitize-amex-export.hs45
-rw-r--r--sort-and-sanitize-the-other-kind-of-amex-export.hs30
2 files changed, 75 insertions, 0 deletions
diff --git a/sort-and-sanitize-amex-export.hs b/sort-and-sanitize-amex-export.hs
new file mode 100644
index 0000000..f0be45c
--- /dev/null
+++ b/sort-and-sanitize-amex-export.hs
@@ -0,0 +1,45 @@
+import Text.CSV
+import Text.Printf (printf)
+
+import Data.List (sort, isPrefixOf, groupBy)
+
+import System.Environment (getArgs)
+
+normAmount :: Field -> Field
+normAmount amt | amt == "" = ""
+ | otherwise = printf "$%.2f" (read amt :: Double)
+
+compressWhitespace :: String -> String
+compressWhitespace x = map head $ groupSpaces x
+ where groupSpaces "" = [""]
+ groupSpaces x = groupBy (\x y -> x==' ' && y==' ') x
+
+mungePayment :: Field -> Field
+mungePayment x | x == "PAYMENT RECEIVED - THANK YOU" = "Assets:Bank:SFLC:Checking:FirstRepublic"
+ | isPrefixOf "FEDEX# " x = "Expenses:Office & Postage:FedEx"
+ | isPrefixOf "JUNCTION NETWORKS " x = "Expenses:Telephony:VoIP:Junction"
+ | isPrefixOf "T-MOBILE" x = "Expenses:Telephony:Mobile:T-Mobile"
+ | isPrefixOf "SPEAKEASY SEATTLE WA" x = "Expenses:Internet:Speakeasy"
+ | isPrefixOf "TELIAX " x = "Expenses:Telephony:VoIP:Teliax"
+ | isPrefixOf "VERIZON" x = "Expenses:Telephony:PSTN:Verizon"
+ | isPrefixOf "VOICEPULSE " x = "Expenses:Telephony:VoIP:VoicePulse"
+ | otherwise = "Expenses:Raw:" ++ compressWhitespace x
+
+newDesc :: String -> String -> String
+newDesc merch refno = compressWhitespace merch ++ parenRef refno
+ where
+ parenRef r | "Reference: " `isPrefixOf` r = concat [" (",drop 11 r,")"]
+ | otherwise = concat [" (",r,")"]
+massageMerchant :: [Field] -> [Field]
+massageMerchant [a,b,c,d,e] = [a,newDesc d b,normAmount c,"",e]
+massageMerchant xs = xs
+
+sanitySort :: [Record] -> [Record]
+sanitySort ts = map (massageMerchant) (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)
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)