diff options
Diffstat (limited to 'src/Main.hs')
-rw-r--r-- | src/Main.hs | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/Main.hs b/src/Main.hs index 133d155..ec602cc 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -1,5 +1,8 @@ {-# LANGUAGE OverloadedStrings #-} +import qualified Data.Text as T +import Control.Monad.IO.Class +import Control.Monad.Logger import System.Directory import Control.Monad.Extra import F2Md.Types @@ -8,13 +11,19 @@ import F2Md.Export import F2Md.Config import System.FilePath +-- TODO: update db on interruption with the latest date +processFeed :: FilePath -> Maybe FilePath -> FeedUserdata -> LoggingT IO () +processFeed root dbPath feed = do + logInfoN $ "Fetching " <> (fuUrl feed) <> "..." + msgs <- liftIO $ toMessagesFromUrl (fuUrl feed) (fuLastUpdated feed) + logInfoN $ "Writing " <> (T.pack $ show $ length msgs) <> " messages..." + liftIO $ mapM_ (writeMessage root) msgs + whenJust dbPath $ \dbPath' -> liftIO $ updateLastUpdated' dbPath' feed msgs + main :: IO () main = do (feeds, maildir, dbPath) <- getUserdata "./.f2m.json" whenJust maildir $ \root -> do mapM_ (createDirectoryIfMissing True) [root </> "new", root </> "cur", root </> "tmp"] - feedMessages <- sequence $ - (\feed -> toMessagesFromUrl (fuUrl feed) (fuLastUpdated feed)) <$> feeds - mapM_ (writeMessage root) $ concat feedMessages - whenJust dbPath $ \dbPath' -> updateLastUpdated dbPath' feeds feedMessages + mapM_ (runStdoutLoggingT . processFeed root dbPath) feeds |