aboutsummaryrefslogtreecommitdiff
path: root/src/Page.hs
diff options
context:
space:
mode:
authorJoris Guyonvarch2015-04-11 11:50:48 +0200
committerJoris Guyonvarch2015-04-11 12:03:22 +0200
commit5977e1454d7738ddb086d37b20337e350e380790 (patch)
treee03261144e3d534434242c1dd037c2a4e4db5a9f /src/Page.hs
downloadad-listener-5977e1454d7738ddb086d37b20337e350e380790.tar.gz
ad-listener-5977e1454d7738ddb086d37b20337e350e380790.tar.bz2
ad-listener-5977e1454d7738ddb086d37b20337e350e380790.zip
Fetch first page ads of a given leboncoin url, fetch also the description page of each item.
Diffstat (limited to 'src/Page.hs')
-rw-r--r--src/Page.hs15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/Page.hs b/src/Page.hs
new file mode 100644
index 0000000..b70db70
--- /dev/null
+++ b/src/Page.hs
@@ -0,0 +1,15 @@
+module Page
+ ( getPage
+ ) where
+
+import Control.Exception (SomeException, try)
+
+import Network.HTTP (simpleHTTP, getRequest, getResponseBody)
+
+getPage :: String -> IO (Either String String)
+getPage url =
+ mapLeft show <$> (try (simpleHTTP (getRequest url) >>= getResponseBody) :: IO (Either SomeException String))
+
+mapLeft :: (a -> c) -> Either a b -> Either c b
+mapLeft f (Left l) = Left (f l)
+mapLeft _ (Right r) = (Right r)