diff options
author | Yuchen Pei <hi@ypei.me> | 2022-05-28 00:48:52 +1000 |
---|---|---|
committer | Yuchen Pei <hi@ypei.me> | 2022-05-28 00:48:52 +1000 |
commit | 20231d809b57c3050fb1cd812ea4c6e66cdaf6fb (patch) | |
tree | f395be8b27b4ff067ad1394fd39d01452433aef1 /src/F2Md/Import.hs | |
parent | caf354c7e5bcb5142d8b4358824d22d3de122f34 (diff) |
time and map updates
Diffstat (limited to 'src/F2Md/Import.hs')
-rw-r--r-- | src/F2Md/Import.hs | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/F2Md/Import.hs b/src/F2Md/Import.hs index ee68578..3ed4d2f 100644 --- a/src/F2Md/Import.hs +++ b/src/F2Md/Import.hs @@ -20,13 +20,13 @@ import Text.Feed.Import import Text.Feed.Types import F2Md.Types -toMessagesFromFile :: FilePath -> IO [Message] -toMessagesFromFile file = do +toMessagesFromFile :: Text -> FilePath -> IO [Message] +toMessagesFromFile url file = do feed <- parseFeedFromFile file case feed of Nothing -> return [] Just feed' -> - mapM (\msg -> toMessage (toFeedMetadata feed') msg) (getFeedItems feed') + mapM (\msg -> toMessage (toFeedMetadata feed' url) msg) (getFeedItems feed') toMessagesFromUrl :: Text -> Maybe ZonedTime -> IO [Message] toMessagesFromUrl url after = do @@ -34,7 +34,7 @@ toMessagesFromUrl url after = do case feed of Nothing -> return [] Just feed' -> catMaybes <$> - mapM (\msg -> toMessage' after (toFeedMetadata feed') msg) (getFeedItems feed') + mapM (\msg -> toMessage' after (toFeedMetadata feed' url) msg) (getFeedItems feed') wgetCommand :: String wgetCommand = "wget -O- 2>/dev/null" @@ -44,24 +44,24 @@ fetchFeed url = readCreateProcess (shell $ wgetCommand ++ " " ++ url) "" toMessage' :: Maybe ZonedTime -> FeedMetadata -> Item -> IO (Maybe Message) toMessage' after feed item + | isNothing date = return Nothing | isNothing after = toMessage feed item >>= return . Just - | isNothing date || zonedTimeToUTC (fromJust after) >= fromJust date = - return Nothing + | zonedTimeToUTC (fromJust after) >= fromJust date = return Nothing | otherwise = toMessage feed item >>= return . Just where date = join $ getItemPublishDate item toMessage :: FeedMetadata -> Item -> IO Message -toMessage (FeedMetadata title author home) item = do +toMessage (FeedMetadata title author home url) item = do messageId <- genMessageId (fromMaybe "" home) (snd <$> getItemId item) return $ Message (fromMaybe title $ orElse (getItemAuthor' item) author) (fromMaybe "Untitled" $ getItemTitle item) - (fromMaybe "" $ getItemDate item) -- default should be current date + (fromJust $ join $ getItemPublishDate item) -- default should be current date messageId (formatBody (getItemLink item) $ (getItemContent item) `orElse` (getItemContent' item) `orElse` (getItemDescription item)) --- title + url getItemAuthor' :: Item -> Maybe Text getItemAuthor' item = case getItemAuthor item of @@ -83,9 +83,9 @@ formatBody link desc = Just link' -> "Link: " <> link' <> "\n\n" in linkText <> (fromMaybe "" desc) -toFeedMetadata :: Feed -> FeedMetadata -toFeedMetadata feed = - FeedMetadata (getFeedTitle feed) (getFeedAuthor feed) (getFeedHome feed) +toFeedMetadata :: Feed -> Text -> FeedMetadata +toFeedMetadata feed url = + FeedMetadata (getFeedTitle feed) (getFeedAuthor feed) (getFeedHome feed) url genMessageId :: Text -> Maybe Text -> IO Text genMessageId feedLink guid = do |