aboutsummaryrefslogtreecommitdiff
path: root/src/Main.hs
diff options
context:
space:
mode:
authorJoris2019-03-10 19:15:45 +0100
committerJoris2019-03-10 19:15:45 +0100
commit8e03a571033a5d02d2287a2b1d1edd8b57aa2462 (patch)
tree03d6965bb65322dbac03edf2d6a30ee856c197f6 /src/Main.hs
parentc41f16ed474376ad8a61a75d8b7f9ef543f359b4 (diff)
Scrap result page and make a CSV of it
Diffstat (limited to 'src/Main.hs')
-rw-r--r--src/Main.hs34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/Main.hs b/src/Main.hs
new file mode 100644
index 0000000..0d527b5
--- /dev/null
+++ b/src/Main.hs
@@ -0,0 +1,34 @@
+module Main (main) where
+
+import Data.Text (Text)
+import qualified Data.Text as T
+import qualified Data.Text.IO as T
+import qualified System.Environment as Env
+import qualified System.Exit as Exit
+
+import qualified CSV
+import Hiking (Hiking (Hiking))
+import qualified Hiking
+import qualified HTTP
+import qualified Scrapper
+
+main :: IO ()
+main = do
+ url <- getUrl
+ hikings <- getHikings url
+ T.putStrLn . CSV.lines . (:) Hiking.header . map Hiking.values $ hikings
+
+getUrl :: IO Text
+getUrl = do
+ args <- Env.getArgs
+ case args of
+ (url:_) -> return $ T.pack url
+ _ -> Exit.die "No url providen"
+
+getHikings :: Text -> IO [Hiking]
+getHikings url = do
+ urls <- Scrapper.hikingsUrls <$> HTTP.get url
+ mapM getHiking urls
+
+getHiking :: Text -> IO Hiking
+getHiking = fmap Scrapper.hiking . HTTP.get