rosa 0.1.3.0 → 0.2.0.0
raw patch · 3 files changed
+20/−26 lines, 3 filesdep ~aesondep ~argparserdep ~base
Dependency ranges changed: aeson, argparser, base, bytestring, process, text, unordered-containers, vector, wreq
Files
- rosa.cabal +6/−6
- src/Json.hs +3/−2
- src/Main.hs +11/−18
rosa.cabal view
@@ -1,5 +1,5 @@ name: rosa-version: 0.1.3.0+version: 0.2.0.0 synopsis: Query the namecoin blockchain description: @@ -12,7 +12,7 @@ license-file: LICENSE author: Rnhmjoj maintainer: micheleguerinirocco@me.com-copyright: (C) Michele Guerini Rocco 2014+copyright: (C) Michele Guerini Rocco 2015 category: Utility build-type: Simple extra-source-files: README.md, LICENSE@@ -28,8 +28,8 @@ hs-source-dirs: src default-language: Haskell2010 other-extensions: RecordWildCards, OverloadedStrings- build-depends: base ==4.7.*, aeson ==0.8.*, text ==1.2.*,- vector ==0.10.*, unordered-containers ==0.2.*,- wreq ==0.3.*, lens >=4.4, bytestring ==0.10.*,- argparser ==0.3.*, process ==1.2.* + build-depends: base >=4.8 && <5.0 , aeson, text,+ vector, unordered-containers,+ wreq, lens >=4.4, bytestring,+ argparser, process ghc-options: -O2
src/Json.hs view
@@ -24,12 +24,13 @@ repr' val lev = case val of Array x -> intercalate ", " $ mapl (\i -> repr' i lev) x- Object x -> drop 1 $ concat $ map (dump x lev) $ H.keys x+ Object x -> newline lev $ concat $ map (dump x lev) $ H.keys x String x -> unpack x Number x -> show x Bool x -> show x Null -> "null"- mapl f v = V.toList $ V.map f v+ mapl f v = V.toList (V.map f v)+ newline n = if n == 1 then id else drop 1 indent l = '\n' : (concat . replicate l) " " dump o l k = concat [indent l, unpack k, ": ", repr' (o |. k) (l+1)]
src/Main.hs view
@@ -1,17 +1,16 @@ {-# LANGUAGE RecordWildCards, OverloadedStrings #-} -import Network.Wreq (get, responseBody)-import Data.Aeson (decode, toJSON)-import Data.Maybe (fromJust)-import Data.HashMap.Strict (delete)+import Json+ import Control.Lens-import Control.Applicative+import Network.Wreq (get, responseBody)+import Data.Aeson (decode, toJSON)+import Data.Maybe (fromJust)+import Data.HashMap.Strict (delete)+import Data.ByteString.Lazy.Char8 (pack) import System.Console.ArgParser import System.Process-import qualified Data.ByteString.Lazy.Char8 as C-import Json - data ProgArgs = ProgArgs { name :: String , url :: String@@ -20,7 +19,6 @@ , raw :: Bool } deriving (Show) - parser :: ParserSpec ProgArgs parser = ProgArgs `parsedBy` reqPos "name" `Descr` "Namecoin name id"@@ -30,37 +28,32 @@ `andBy` boolFlag "block" `Descr` "Show blockchain data (require local connecton)" `andBy` boolFlag "raw" `Descr` "Print raw JSON data" - interface :: IO (CmdLnInterface ProgArgs) interface = (`setAppDescr` "Query the namecoin blockchain") <$> (`setAppEpilog` "Stat rosa pristina nomine, nomina nuda tenemus.") <$> mkApp parser - main :: IO () main = interface >>= flip runApp exec - exec :: ProgArgs -> IO ()-exec ProgArgs{..} = do+exec ProgArgs{..} = if dnschain then handleDnschain url name raw else handleLocal name block - handleLocal :: String -> Bool -> IO () handleLocal name block = do out <- readProcess "namecoind" ["name_show", name] ""- case decode (C.pack out) of+ case decode (pack out) of Just res -> do pprint $ reparse (res |: "value") if block then pprint extra else return () where- reparse = fromJust . decode . C.pack- extra = toJSON $ delete "value" res+ reparse = fromJust . decode . pack+ extra = toJSON (delete "value" res) Nothing -> putStrLn "Error parsing data"- handleDnschain :: String -> String -> Bool -> IO () handleDnschain url name raw = do