Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Xml Error Refactor
-- a huge number of imports above
main :: IO ()
main = do
createDirectoryIfMissing True "output"
env <- getAppEnv
let connInfo = dbConnectInfo env
db <- dbConnection connInfo
queryText <- BS.readFile "db/errors.sql"
results <- query_ db (Query queryText)
date <- getCurrentTime
timeZone <- getCurrentTimeZone
let outputs = massageAll date timeZone results
let csvOutput = toCSV outputs
writeFile "output/results.csv" csvOutput
liftIO $ ftpFile env csvOutput
email (Email (emailFromAddress env) (emailCCAddresses env) (emailToAddresses env) "XML Error Notifications") "output/results.csv"
print $ "Outputed " ++ show (length outputs) ++ " rows"
-- lots more code below
main :: IO ()
main = do
config <- getAppConfig
filename' <- filename
results <- fetchResults config
transformed <- transform results
let outputPath = "output/" ++ filename'
encoded = encode transformed
createDirectoryIfMissing True "output"
writeFile outputPath encoded
ftp config outputPath
email config outputPath
print $ "Outputed " ++ show (length transformed) ++ " rows for file " ++ filename'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment