sloane 0.1.4 → 0.1.5
raw patch · 4 files changed
+32/−8 lines, 4 filesdep ~url
Dependency ranges changed: url
Files
- LICENSE +1/−1
- README.md +5/−0
- sloane.cabal +2/−2
- sloane.hs +24/−5
LICENSE view
@@ -1,4 +1,4 @@-Copyright (c)2012, Anders Claesson+Copyright (c) 2012, 2013, Anders Claesson All rights reserved.
README.md view
@@ -19,6 +19,7 @@ Common flags: -k --keys=KEYS Keys of fields to print (default: SN) -a --all Print all fields+ -u --url Only print urls of found entries -n --limit=INT Limit the number of entries retrieved (default: 5) -? --help Display help message -V --version Print version information@@ -56,6 +57,10 @@ S A006531 1,1,3,19,183,2371,38703,763099,17648823,468603091,14050842303, N A006531 Semiorders on n elements.++Look at those 3 results in firefox:++ $ firefox `sloane --url -n3 "(2+2)-free posets"` Keys ----
sloane.cabal view
@@ -1,5 +1,5 @@ Name: sloane-Version: 0.1.4+Version: 0.1.5 Synopsis: A command line interface to Sloane's On-Line Encyclopedia of Integer Sequences Description: A command line interface to Sloane's On-Line Encyclopedia of Integer Sequences. For usage see <http://github.com/akc/sloane>.@@ -20,4 +20,4 @@ Executable sloane Main-is: sloane.hs- Build-depends: base >= 3 && < 5, cmdargs, HTTP, url+ Build-depends: base >= 3 && < 5, cmdargs, HTTP, url >=2
sloane.hs view
@@ -1,9 +1,14 @@ {-# LANGUAGE DeriveDataTypeable #-} +-- |+-- Copyright : Anders Claesson 2012, 2013+-- Maintainer : Anders Claesson <anders.claesson@gmail.com>+--+ import Prelude hiding (all) import System.Console.CmdArgs import Data.Maybe (fromJust)-import Control.Monad (when)+import Control.Monad (when, guard) import Network.HTTP (simpleHTTP, getRequest, getResponseBody) import Network.URL (importURL, exportURL, add_param) @@ -11,11 +16,13 @@ type Query = String type Key = Char -oeisURL = fromJust $ importURL "http://oeis.org/search?fmt=text"+oeisHost = "http://oeis.org"+oeisURL = fromJust . importURL $ oeisHost ++ "/search?fmt=text" oeisKeys = "ISTUVWXNDHFYAOEeptoKC" data Sloane = Sloane { keys :: String , all :: Bool+ , url :: Bool , limit :: Int , terms :: String }@@ -23,16 +30,24 @@ sloane = cmdArgsMode $ Sloane { keys = "SN" &= typ "KEYS" &= help "Keys of fields to print (default: SN)"- , all = False &= help "Print all fields"+ , all = False &= name "a" &= help "Print all fields"+ , url = False &= name "u" &= help "Print urls of found entries" , limit = 5 &= name "n" &= help "Limit the number of entries retrieved (default: 5)" , terms = def &= argPos 0 &= typ "SEARCH-TERMS" }- &= versionArg [summary "sloane 0.1.4"]+ &= versionArg [summary "sloane 0.1.5"] &= summary "Search Sloane's On-Line Encyclopedia of Integer Sequences" select :: [Key] -> OEISEntries -> OEISEntries select ks = unlines . filter (\xs -> null xs || head xs `elem` ks) . lines +urls :: OEISEntries -> String+urls es = unlines $ do+ ids <- lines $ select "I" es+ guard $ not (null ids)+ let aNum = (words ids) !! 1+ return $ oeisHost ++ "/" ++ aNum+ searchOEIS :: Int -> Query -> IO OEISEntries searchOEIS n s = do trim `fmap` (simpleHTTP (getRequest url) >>= getResponseBody)@@ -45,4 +60,8 @@ result <- searchOEIS (limit args) . filter (`notElem` "[]") $ terms args when (not $ null result) $ do putStrLn ""- putStrLn $ if all args then result else select (keys args) result+ if (url args)+ then+ putStrLn $ urls result+ else+ putStrLn $ if all args then result else select (keys args) result