Skip to content

Instantly share code, notes, and snippets.

@AlistairB
Last active November 27, 2017 00:11
Show Gist options
  • Save AlistairB/a7fdc2ccfd01d5955e25950fc656fe30 to your computer and use it in GitHub Desktop.
Save AlistairB/a7fdc2ccfd01d5955e25950fc656fe30 to your computer and use it in GitHub Desktop.
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