imgurder 1.0 → 1.1
raw patch · 4 files changed
+19/−92 lines, 4 files
Files
- LICENSE +1/−1
- imgurder.cabal +3/−4
- imgurder.hs +0/−87
- main.hs +15/−0
LICENSE view
@@ -1,5 +1,5 @@ Dan Colish <dcolish@gmail.com>-Copyright (c) 2010+Copyright (c) 2010, 2011 All rights reserved Redistribution and use in source and binary forms, with or without
imgurder.cabal view
@@ -1,5 +1,5 @@ Name: imgurder-Version: 1.0+Version: 1.1 License: BSD3 License-file: LICENSE Author: Dan Colish@@ -8,11 +8,10 @@ Cabal-Version: >=1.2 Synopsis: Uploader for Imgur Category: Web-Description: A simple uploader for the Imgur api. You should register- for an api key+Description: A simple uploader for the Imgur api. Executable imgurder- Main-is: imgurder.hs+ Main-is: main.hs Build-Depends: base >= 3 && < 5, hxt-xpath >= 8.5.4, hxt >= 8.3.2, curl >= 1.3.5, directory >= 1.0.0.3, haskell98 >= 1
− imgurder.hs
@@ -1,87 +0,0 @@------ Imgur Uploader--- Dan Colish <dcolish@gmail.com>--- Copyright (c) 2010--- All rights reserved------ Usage: runghc imgur.hs <filepath>--- Be sure to add an api key before using it and put it in ~/imgurder--- A sample configuration file would be:--- `echo '<your api key>' > ~/.imgurder`-----import Data.IORef-import Data.List-import Data.Maybe-import Data.Tree.Class-import Network.Curl-import System (getArgs)-import System.Directory-import System.IO-import Text.XML.HXT.DOM.TypeDefs-import qualified Text.XML.HXT.DOM.XmlNode as N-import qualified Text.XML.HXT.Parser.XmlParsec as H-import qualified Text.XML.HXT.XPath.XPathEval as X---myCurlPost :: String -> String -> [HttpPost]-myCurlPost apikey myImage =- [ HttpPost { postName = "image"- , contentType = Nothing , content = ContentFile myImage- , extraHeaders = []- , showName = Nothing },- HttpPost { postName = "key"- , contentType = Nothing- , content = ContentString apikey- , extraHeaders = []- , showName = Nothing }]---pathTags :: [String]-pathTags = [ "/rsp/image_hash"- ,"/rsp/delete_hash"- ,"/rsp/original_image"- ,"/rsp/large_thumbnail"- ,"/rsp/small_thumbnail"- ,"/rsp/imgur_page"- ,"/rsp/delete_page" ]---xpathQN:: String -> XmlTree -> String-xpathQN str = fromJust . N.getQualifiedName . getNode . head . X.getXPath str---xpathTxt:: String -> XmlTree -> String-xpathTxt str = fromJust . N.getText . head . getChildren . head . X.getXPath str---keyVal :: XmlTree -> String -> String-keyVal res str = unwords [(xpathQN str res), " = ", (xpathTxt str res)]---formattedResult :: XmlTree -> [String]-formattedResult res = map (keyVal res) pathTags---loadConf :: IO String-loadConf = do- h <- getHomeDirectory- key <- readFile (h ++ "/.imgurder")- return key---main :: IO ()-main = withCurlDo $ do- [file] <- getArgs- key <- loadConf- initialize- ref <- newIORef []- curlMultiPost "http://imgur.com/api/upload.xml"- [CurlWriteFunction (gatherOutput ref), CurlVerbose False]- $ myCurlPost key file- response <- fmap reverse $ readIORef ref- putStrLn "== Imgur Upload Complete ==\n"- putStrLn . unlines . formattedResult . result $ response- where- result = head . H.xread . concatMap (unwords.tail.lines)-
+ main.hs view
@@ -0,0 +1,15 @@+import Network.Imgurder+import System (getArgs)+import System.IO+import System.Exit++key :: String+key = "a05aaffbb595c38c2cd2d54d4c57eb3f"++main :: IO ()+main = do+ [file] <- getArgs+ imgurUpload <- upload key file+ case imgurUpload of+ Right a -> print a+ Left a -> print a -- Uknown Error happened