rosa (empty) → 0.1.0.0
raw patch · 5 files changed
+130/−0 lines, 5 filesdep +aesondep +argparserdep +basesetup-changed
Dependencies added: aeson, argparser, base, bytestring, lens, process, text, unordered-containers, vector, wreq
Files
- LICENSE +3/−0
- Main.hs +57/−0
- README.md +39/−0
- Setup.hs +2/−0
- rosa.cabal +29/−0
+ LICENSE view
@@ -0,0 +1,3 @@+Dual licensed under the MIT and GPL licenses:+http://www.opensource.org/licenses/mit-license.php+http://www.gnu.org/licenses/gpl.html
+ Main.hs view
@@ -0,0 +1,57 @@+{-# LANGUAGE RecordWildCards, OverloadedStrings #-}++import Network.Wreq (get, responseBody)+import Data.Aeson (decode, toJSON)+import Data.Maybe (fromJust)+import Data.HashMap.Strict (delete)+import Control.Monad (when)+import Control.Lens++import qualified Data.ByteString.Lazy.Char8 as C+import System.Console.ArgParser+import System.Process++import Json++data ProgArgs = ProgArgs+ { name :: String+ , url :: String+ , local :: Bool+ , block :: Bool+ , raw :: Bool+ } deriving (Show)++parser :: ParserSpec ProgArgs+parser = ProgArgs+ `parsedBy` reqPos "name" `Descr` "Namecoin name id"+ `andBy` optPos "http://dns.dnschain.net/" "url"+ `Descr` "Use custom dnschain API url"+ `andBy` boolFlag "local" `Descr` "Use local namecoind db"+ `andBy` boolFlag "block" `Descr` "Show blockchain data (require local connecton)"+ `andBy` boolFlag "raw" `Descr` "Print raw JSON data"++exec :: ProgArgs -> IO ()+exec args@ProgArgs{..} =+ if local+ then do+ out <- readProcess "namecoind" ["name_show", name] ""+ case decode (C.pack out) of+ Just res -> do+ putStrLn (repr value)+ when block $ putStrLn (repr extra)+ where+ value = fromJust . decode . C.pack $ res |: "value"+ extra = toJSON $ delete "value" res+ Nothing -> putStrLn "Error parsing data"+ else do+ req <- get (url ++ name)+ let body = req ^. responseBody+ if raw+ then print body+ else putStrLn $+ case decode body of+ Just res -> repr res+ Nothing -> "Error parsing data"++main :: IO ()+main = mkApp parser >>= flip runApp exec
+ README.md view
@@ -0,0 +1,39 @@+# Rosa+## Query the namecoin blockchain++Rosa is a commmand line tool to query the namecoin blockhain.++It gets the JSON value of a name and other data using namecoind local server or the dnschain REST api and displays it in a pretty format.++### Usage+Run rosa -h for help++Show the value for a name with++ $ rosa id/rnhmjoj+ bitcoin: 14JYCRLovTiNtcXNoUv2fCwnU9xyX2vZE7+ bitmessage: BM-87izDq7zoLWnne8cWq4Tb3iq4dA4MkL18fm+ email: micheleguerinirocco@me.com+ photo_url: http://0.gravatar.com/avatar/28111022fb94798555c8d3efc1f288ed+ gpg:+ fpr: 85FA62051FD9C90EE553EE00428F8F8D351F12A6+ v: pka1+ namecoin: N3zSdWjXJwtnZHYdRXymSzVzgooDMpAvEw+ name: Michele Guerini Rocco++Connect to namecoind server for blockhain data++ $ rosa d/namechain -lb+ ip: 83.96.168.183+ map:+ *:+ ip: 83.96.168.183+ expires_in: 13999.0+ address: N44Q9pqv1KtfmeEH79Q68evanXdGf6edf6+ name: d/namechain+ txid: 425cd3cd854a18bb0494f139ae4b89b9f2892d3a9b865d8f2a704eea15723f35++### License+Dual licensed under the MIT and GPL licenses: +http://www.opensource.org/licenses/mit-license.php +http://www.gnu.org/licenses/gpl.html
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ rosa.cabal view
@@ -0,0 +1,29 @@+name: rosa+version: 0.1.0.0+synopsis: Query the namecoin blockchain+description:++ Rosa is a commmand line tool to query the namecoin blockhain.+ It gets the JSON value of a name and other infos using namecoind+ local server or the dnschain REST api and display them in a pretty + format.+ +license: MIT+license-file: LICENSE+author: Rnhmjoj+maintainer: micheleguerinirocco@me.com+copyright: (C) Michele Guerini Rocco 2014+category: Utility+build-type: Simple+extra-source-files: README.md, LICENSE+cabal-version: >=1.10++executable rosa+ main-is: Main.hs+ 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.* + ghc-options: -O2