packages feed

gscholar-rss 0.2.5.0 → 0.3.0.0

raw patch · 3 files changed

+57/−30 lines, 3 files

Files

NEWS view
@@ -1,3 +1,9 @@+0.3.0.0+-------++- Clearer errors are now displayed on failed parse+- Thanks to Chihiro Fukazawa for pointing it out+ 0.2.5.0 ------- 
gscholar-rss.cabal view
@@ -1,5 +1,5 @@ name:                gscholar-rss-version:             0.2.5.0+version:             0.3.0.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>@@ -20,6 +20,8 @@  executable gscholar-rss   main-is:             Main.hs+  other-modules:       Paths_gscholar_rss+  autogen-modules:     Paths_gscholar_rss   build-depends:       base == 4.*,                        feed >= 1.0.1.0 && < 1.4,                        http-conduit == 2.3.*,@@ -29,6 +31,7 @@                        xml-types == 0.3.*   hs-source-dirs:      src   default-language:    Haskell2010+  ghc-options:         -Wall  source-repository head     type:     darcs
src/Main.hs view
@@ -13,41 +13,44 @@ import Text.RSS.Syntax import Text.RSS.Export +import qualified Paths_gscholar_rss as P+import qualified Control.Exception  as E 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.Version       as V import qualified Data.XML.Types     as XT import qualified Text.Atom.Feed     as AF import qualified Text.URI           as U - main :: IO ()-main = -- get args-       map T.pack <$> getArgs >>= \as ->+main = errorPress work+    where+          work :: IO ()+          work =+               -- get args+               map T.pack <$> getArgs >>= \as -> -       -- malformed input-       if null as ||-          length as > 1 ||-          head as `elem` ["--help", "-h"]-       then putStrLn helps-       else+               -- malformed input+               if null as ||+                  length as > 1 ||+                  head as `elem` ["--help", "-h", "-v", "--version"]+               then putStrLn helps+               else -       -- scrape-       let url = head as in-       scrapeGet url (page url) >>= \p ->-       printRSS url p+               -- scrape+               let url = head as in+               scrapeGet url (page url) >>= \p ->+               printRSS url p -    where           scrapeGet :: URL -> Scraper T.Text a -> IO a           scrapeGet url s = getURLBody url  >>= \b ->-                            let r = maybe (error errs)+                            let r = maybe (error "Nothing in scrapeGet")                                           id                                           (scrapeStringLike b s)                             in return r-- ----------- -- TYPES -- -----------@@ -89,15 +92,15 @@  -- Title: channel title buildRSS :: Title -> Page -> RSS-buildRSS pt (Page t u as) =-        (nullRSS "ERRORE-T" "ERRORE-L") {+buildRSS pt (Page _ u as) =+        (nullRSS "NULL-WRONG-T" "NULL-WRONG-L") {           rssAttrs   = [dublinNamespace],           rssChannel = (nullChannel pt u) {rssItems = map buildItem as} }     where           buildItem :: Article -> RSSItem-          buildItem (Article t u a d) =+          buildItem (Article t wu a d) =                 (nullItem t) {-                    rssItemLink = Just $ u,+                    rssItemLink = Just wu,                     -- rssItemAuthor = Just $ a,                     rssItemOther = [dcCreator a],                     rssItemDescription = Just d }@@ -113,6 +116,7 @@                 ("xmlns:dc",                  [XT.ContentText "http://purl.org/dc/elements/1.1/"]) + ------------- -- GET/PUT -- -------------@@ -125,7 +129,7 @@  feedTitle :: URL -> Title feedTitle url = case lookup "q" (U.queryToPairs $ T.unpack url) of-                  Nothing -> "Error: title not found"+                  Nothing -> "Wrong: title not found"                   Just t  -> "gscholar-rss: " <> T.pack t  -- removes 'ots' and 'sig' from a google books url@@ -140,7 +144,7 @@             T.pack . show $ u'         | otherwise = url     where-          uri = maybe (error "gclean: misparse")+          uri = maybe (error "misparse in gclean")                       id                       (U.parseURI $ T.unpack url) @@ -149,20 +153,34 @@                     Just rn -> L.isPrefixOf "books.google" rn            filtFun :: (String, String) -> Bool-          filtFun (l, _) = not (elem l ["ots", "sig"])+          filtFun (l, _) = notElem l ["ots", "sig"]  printRSS :: URL -> Page -> IO () printRSS url s =     case textRSS . buildRSS (feedTitle url) $ s of-      Nothing -> error errs-      Just s  -> TLI.putStrLn s+      Nothing -> error "Nothing in printRSS"+      Just ms -> TLI.putStrLn ms  helps :: String helps = unlines     ["invoke as: gscholar-rss <search-url>",      "manual and examples: http://ariis.it/static/articles/gscholar-rss/page.html",-     "v 0.2.5.0, released under the GPLv3"]+     version ++ " -- GPLv3"] -errs :: String-errs  = "Could not parse, please report to fa-ml@ariis.it"++-- error handling lifted from ansi-terminal-game+-- wraps error call with version/contact info+errorPress :: IO () -> IO ()+errorPress m = E.catch m errorDisplay+    where+          errorDisplay :: E.SomeException -> IO ()+          errorDisplay se =+              putStrLn . unlines $+                  [show se,+                   "gscholar-rss " ++ version,+                   "Can't fix this? Please report to <fa-ml@ariis.it>"]++-- todo autopick version+version :: String+version = 'v' : V.showVersion P.version