diff options
Diffstat (limited to 'src/F2Md/Import.hs')
-rw-r--r-- | src/F2Md/Import.hs | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/src/F2Md/Import.hs b/src/F2Md/Import.hs index 7c8110c..80dfa54 100644 --- a/src/F2Md/Import.hs +++ b/src/F2Md/Import.hs @@ -39,17 +39,16 @@ import Data.Generics import Text.RSS.Syntax hiding (RSSItem) import Data.XML.Types import Text.Feed.Import -import Text.Feed.Types import F2Md.Types import Crypto.Hash toMessagesFromUrl :: Text -> Maybe ZonedTime -> IO [Message] toMessagesFromUrl url after = do - feed <- parseFeedString <$> (fetchFeed $ T.unpack url) + feed <- parseFeedString <$> fetchFeed (T.unpack url) case feed of Nothing -> return [] Just feed' -> return $ - sortOn (\msg -> zonedTimeToUTC (mDate msg)) $ catMaybes $ + sortOn (zonedTimeToUTC . mDate) $ catMaybes $ toMessage' after (toFeedMetadata feed' url) <$> getFeedItems feed' wgetCommand :: String @@ -76,12 +75,12 @@ toMessage (FeedMetadata title author home url) item = body url where body = - (formatBody (getItemLink item) (getItemEnclosure item) $ + formatBody (getItemLink item) (getItemEnclosure item) $ (getItemContent item) `orElse` (getItemContent' item) `orElse` - (getItemDescription item)) + (getItemDescription item) messageId = - "<" <> (T.pack $ show $ hashWith MD5 (encodeUtf8 body)) <> "@" <> - (T.map hyphenateNonAlNum url) <> ".gnu" <> ">" + "<" <> T.pack (show $ hashWith MD5 (encodeUtf8 body)) <> "@" <> + T.map hyphenateNonAlNum url <> ".gnu" <> ">" getItemAuthor' :: Item -> Maybe Text @@ -92,8 +91,7 @@ getItemAuthor' item = case getItemAuthor item of getItemContent' :: Item -> Maybe Text getItemContent' (RSSItem item) = - (fmap (T.concat . elementText) . listToMaybe . - filter (\e -> namePrefix (elementName e) == Just "content")) + (fmap (T.concat . elementText) . find (\e -> namePrefix (elementName e) == Just "content")) $ rssItemOther item getItemContent' _ = Nothing @@ -110,13 +108,12 @@ formatBody link encl desc = Just (url, Just ty, Just len) -> urlPt url <> " (" <> ty <> ", " <> lenPt len <> ")\n\n" where urlPt url = "Enclosure: <" <> url <> ">" - lenPt len = (T.pack $ show len) <> " bytes" + lenPt len = T.pack (show len) <> " bytes" in - linkText <> enclText <> (fromMaybe "" desc) + linkText <> enclText <> fromMaybe "" desc toFeedMetadata :: Feed -> Text -> FeedMetadata -toFeedMetadata feed url = - FeedMetadata (getFeedTitle feed) (getFeedAuthor feed) (getFeedHome feed) url +toFeedMetadata feed = FeedMetadata (getFeedTitle feed) (getFeedAuthor feed) (getFeedHome feed) hyphenateNonAlNum :: Char -> Char hyphenateNonAlNum c |