aboutsummaryrefslogtreecommitdiff
path: root/src/Main.hs
blob: 0d527b5bb38825512f48d69556cf10ab671ce644 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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