@@ -1,4 +1,5 @@
11{-# LANGUAGE OverloadedStrings, ScopedTypeVariables #-}
2+-- | generate the ISO31661.hs file from the wikipedia html file
23module Main where
34
45import Text.HTML.TagSoup
@@ -9,15 +10,21 @@ import Data.Maybe (mapMaybe)
910import Data.Monoid ((<>))
1011import Data.List (foldl')
1112
13+
14+-- | entry point
1215main :: IO()
1316main = do
17+ -- read from a local version
1418 txt <- T.readFile "data/ISO 3166-1 alpha-2 - Wikipedia, the free encyclopedia.html"
19+ -- extract data
1520 let assocs = extract txt
21+ -- generate Haskell code
1622 let haskell=generate assocs
23+ -- write file
1724 T.writeFile "src/Data/CountryCodes/ISO31661.hs" haskell
1825 return ()
1926
20−
27+-- | extract tuples (code,name) from wikipedia file
2128extract :: T.Text -> [(T.Text,T.Text)]
2229extract txt =
2330 let tts=parseTags txt
@@ -40,6 +47,7 @@ extract txt =
4047 in Just (cid,name)
4148 ) rows
4249
50+-- | generate haskell code
4351generate :: [(T.Text,T.Text)] -> T.Text
4452generate assocs =
4553 let
@@ -115,5 +123,6 @@ generate assocs =
115123 toName :: T.Text -> (T.Text,T.Text) -> T.Text
116124 toName acc (i,n) = acc <> nl <> "toName " <> i <> " = \"" <> n <> "\""
117125
126+-- | new line
118127nl :: T.Text
119128nl = "\n"