gscholar-rss 0.2.4.1 → 0.2.5.0
raw patch · 3 files changed
+47/−20 lines, 3 filesdep +xml-types
Dependencies added: xml-types
Files
- NEWS +9/−0
- gscholar-rss.cabal +6/−5
- src/Main.hs +32/−15
NEWS view
@@ -1,3 +1,12 @@+0.2.5.0+-------++- Feed not validates on W3C validator, specifically:+ - switched from <author> to <dc:author>+ - added a valid url to <channel>+- Thanks to Damien Couroussé for reporting the validator problems++ 0.2.4.1 -------
gscholar-rss.cabal view
@@ -1,5 +1,5 @@ name: gscholar-rss-version: 0.2.4.1+version: 0.2.5.0 synopsis: scrapes google scholar, provides RSS feed description: A simple Google Scholar scraper, providing RSS/Atom feeds. Check <http://ariis.it/static/articles/gscholar-rss/page.html homepage>@@ -8,7 +8,7 @@ license-file: LICENSE author: Francesco Ariis maintainer: fa-ml@ariis.it-copyright: 2018-2019 © Francesco Ariis+copyright: 2018-2020 © Francesco Ariis homepage: http://www.ariis.it/static/articles/gscholar-rss/page.html category: Web, Utils build-type: Simple@@ -21,11 +21,12 @@ executable gscholar-rss main-is: Main.hs build-depends: base == 4.*,- scalpel-core >= 0.5 && < 0.7, feed >= 1.0.1.0 && < 1.4,- text == 1.2.*, http-conduit == 2.3.*,- uri == 0.1.*+ scalpel-core >= 0.5 && < 0.7,+ text == 1.2.*,+ uri == 0.1.*,+ xml-types == 0.3.* hs-source-dirs: src default-language: Haskell2010
src/Main.hs view
@@ -13,12 +13,14 @@ import Text.RSS.Syntax import Text.RSS.Export +import qualified Data.List as L+import qualified Data.String as DS import qualified Data.Text as T import qualified Data.Text.Lazy.IO as TLI import qualified Data.Text.Encoding as TE-import qualified Data.String as DS+import qualified Data.XML.Types as XT+import qualified Text.Atom.Feed as AF import qualified Text.URI as U-import qualified Data.List as L main :: IO ()@@ -34,7 +36,7 @@ -- scrape let url = head as in- scrapeGet url page >>= \p ->+ scrapeGet url (page url) >>= \p -> printRSS url p where@@ -51,11 +53,12 @@ ----------- type Title = T.Text-data Page = Page Title [Article]+type URL = T.Text+data Page = Page Title URL [Article] deriving (Show, Eq)+ -- URL: url of the feed/page type Author = T.Text-type URL = T.Text type Description = T.Text data Article = Article Title URL Author Description deriving (Show, Eq)@@ -65,9 +68,10 @@ -- SCRAPE -- ------------ -page :: Scraper T.Text Page-page = Page <$> text "title"- <*> chroot ("div" @: ["id" @= "gs_res_ccl_mid"]) entries+page :: URL -> Scraper T.Text Page+page u = Page <$> text "title"+ <*> pure u+ <*> chroot ("div" @: ["id" @= "gs_res_ccl_mid"]) entries entries :: Scraper T.Text [Article] entries = chroots ("div" @: [hasClass "gs_ri"]) paper@@ -83,20 +87,32 @@ -- todo rimuovi span? -- todo aggiungi test -buildRSS :: URL -> Page -> RSS-buildRSS u (Page t as) =- (nullRSS "rss title" "link") {- rssChannel = (nullChannel u "link") {- rssItems = map buildItem as }}+-- Title: channel title+buildRSS :: Title -> Page -> RSS+buildRSS pt (Page t u as) =+ (nullRSS "ERRORE-T" "ERRORE-L") {+ rssAttrs = [dublinNamespace],+ rssChannel = (nullChannel pt u) {rssItems = map buildItem as} } where buildItem :: Article -> RSSItem buildItem (Article t u a d) = (nullItem t) { rssItemLink = Just $ u,- rssItemAuthor = Just $ a,+ -- rssItemAuthor = Just $ a,+ rssItemOther = [dcCreator a], rssItemDescription = Just d } + -- http://www.rssboard.org/rss-profile#namespace-elements-dublin-creator+ dcCreator :: Author -> XT.Element+ dcCreator a = XT.Element "dc:creator" []+ [XT.NodeContent $ XT.ContentText a] + -- needed for dcCreator+ dublinNamespace :: AF.Attr+ dublinNamespace =+ ("xmlns:dc",+ [XT.ContentText "http://purl.org/dc/elements/1.1/"])+ ------------- -- GET/PUT -- -------------@@ -144,7 +160,8 @@ helps :: String helps = unlines ["invoke as: gscholar-rss <search-url>",- "manual and examples: http://ariis.it/static/articles/gscholar-rss/page.html"]+ "manual and examples: http://ariis.it/static/articles/gscholar-rss/page.html",+ "v 0.2.5.0, released under the GPLv3"] errs :: String errs = "Could not parse, please report to fa-ml@ariis.it"