From b9368ee15435cc709148b75061544304b59eef3a Mon Sep 17 00:00:00 2001 From: Jeena Date: Sun, 23 Nov 2014 18:07:47 +0100 Subject: [PATCH] added first browser tests --- .gitignore | 1 + browser.hs | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 browser.hs diff --git a/.gitignore b/.gitignore index eba1e11..41e37c3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.hi *.o cnb +browser diff --git a/browser.hs b/browser.hs new file mode 100644 index 0000000..9385906 --- /dev/null +++ b/browser.hs @@ -0,0 +1,22 @@ +{-# LANGUAGE OverloadedStrings #-} + +import Network.HTTP.Conduit +import qualified Data.ByteString.Lazy as L +import qualified Data.ByteString.Char8 as C + +main :: IO () +main = do + b <- getTweet "https://twitter.com/YELLEtweets/status/535845076316860417" + case b of + Nothing -> putStrLn "nothing to pring" + Just body -> putStrLn body + +getTweet :: String -> Maybe String +getTweet url = do + initReq <- parseUrl url + let req = initReq { secure = True } -- Turn on https + response <- withManager $ httpLbs req + body <- responseBody response + case body of + empty -> return Nothing + _ -> return Just (L.unpack body)