sloane 0.1.2 → 0.1.3
raw patch · 3 files changed
+13/−19 lines, 3 files
Files
- README.md +1/−1
- sloane.cabal +1/−1
- sloane.hs +11/−17
README.md view
@@ -1,7 +1,7 @@ sloane ====== -A command line interface to Sloane's On-Line Encyclopedia of Integer Sequences (OEIS)+A command line interface to Sloane's [On-Line Encyclopedia of Integer Sequences (OEIS)](http://oeis.org) Install -------
sloane.cabal view
@@ -1,5 +1,5 @@ Name: sloane-Version: 0.1.2+Version: 0.1.3 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>.
sloane.hs view
@@ -2,13 +2,12 @@ import Prelude hiding (all) import System.Console.CmdArgs-import Data.List (groupBy) import Data.Maybe (fromJust) import Control.Monad (when) import Network.HTTP (simpleHTTP, getRequest, getResponseBody) import Network.URL (importURL, exportURL, add_param) -type OEISEntry = String+type OEISEntries = String type Query = String type Key = Char @@ -29,27 +28,22 @@ , 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.2"]+ &= versionArg [summary "sloane 0.1.3"] &= summary "Search Sloane's On-Line Encyclopedia of Integer Sequences" -nonempty = not . null--parse :: String -> [OEISEntry]-parse = map (unlines . filter nonempty) . groupBy (\_ x -> nonempty x)- . map (drop 1) . reverse . drop 2 . reverse . drop 5 . lines--select :: [Key] -> OEISEntry -> OEISEntry-select ks = unlines . filter (\(k:_) -> k `elem` ks) . lines+select :: [Key] -> OEISEntries -> OEISEntries+select ks = unlines . filter (\xs -> null xs || head xs `elem` ks) . lines -searchOEIS :: Int -> Query -> IO [OEISEntry]+searchOEIS :: Int -> Query -> IO OEISEntries searchOEIS n s = do- parse `fmap` (simpleHTTP (getRequest url) >>= getResponseBody)+ trim `fmap` (simpleHTTP (getRequest url) >>= getResponseBody) where+ trim = unlines . map (drop 1) . reverse . drop 2 . reverse . drop 5 . lines url = exportURL $ oeisURL `add_param` ("n", show n) `add_param` ("q", s) main = do args <- cmdArgsRun sloane- es <- searchOEIS (limit args) . filter (`notElem` "[]") $ terms args- when (nonempty es) $ putStrLn ""- let ks = if all args then oeisKeys else keys args- mapM_ (putStrLn . select ks) es+ 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