diff --git a/app/Main.hs b/app/Main.hs index f0620f2..9105271 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -6,7 +6,7 @@ import Parse main :: IO () main = do - putStrLn "[CountryCode] - Country Codes available\n\ + putStrLn "\n[CountryCode] - Country Codes available\n\ \AU Australia\n\ \BR Brazil\n\ \CA Canada\n\ @@ -17,37 +17,28 @@ main = do \GB United Kingdom\n\ \Input Country Code - \n" countryCodeInput <- getLine - putStrLn "[Year] - Country Codes available\n\ + putStrLn "\n[Year] - Country Codes available\n\ \2019 Calendar year 2019\n\ \2020 Calendar year 2020\n\ \2021 Calendar year 2021\n\ \Input Year Code - \n" yearInput <- getLine let url = "https://date.nager.at/api/v2/publicholidays/"++yearInput++"/"++countryCodeInput - print "Downloading..." + putStrLn "\nDownloading..." json <- download url - print "Parsing..." + putStrLn "\nParsing..." case parse json of Left err -> print err Right recs -> do - -- print recs - putStrLn "Saving on DB..." - -- putStrLn "\n****************" + putStrLn "\nSaving on DB...\n" conn <- initialiseDB insertDB conn recs insertSB conn recs insertLB conn recs - putStrLn "Done!" - putStrLn "\n****************" res <- queryDB conn countryCodeInput - putStrLn "\n****************" - -- putStrLn "Before Formatting Query" - -- putStr $ show res - -- putStrLn "\n****************" - putStrLn $ "\nList of Holidays in " ++ countryCodeInput + putStrLn $ "\nTotal List of Holidays in " ++ countryCodeInput ++ " in the calendar year "++ yearInput let converRes = sqlRowToString res mapM_ putStrLn converRes - putStrLn "\n****************" putStrLn "\nSee the holidays between specific dates... " putStrLn "\nInput the start date [DD-MMM-YY] " startDate <- getLine @@ -56,35 +47,32 @@ main = do dateSort <- selectHolidaysInDateRange conn startDate endDate putStrLn $ "\nHolidays between " ++startDate ++ " and " ++ endDate ++ " are : \n" -- TODO Format the dates - print (concat dateSort) - putStrLn "\n****************" - putStrLn "\nDo you want to see Global (or Local) holidays? Type Y for global and N for local" + mapM_ putStrLn $ dateSort + putStrLn $ "\nDo you want to see International or Local holidays in " ++ countryCodeInput ++" ?\nType Y for global and N for local -" inputGlobal <- getChar - putStrLn "\nGlobal/Local Holidays are : \n" case inputGlobal of 'Y' -> do + putStrLn "\nInternational Holidays are : \n" names<- getLocalNames conn True - print $ show names + putStrLn $ unlines names 'y' -> do + putStrLn "\nInternational Holidays are : \n" names<- getLocalNames conn True - print $ show names + putStrLn $ unlines names 'N' -> do + putStrLn "\nLocal Holidays are : \n" names<- getLocalNames conn False - print $ show names + putStrLn $ unlines names 'n' -> do + putStrLn "\nLocal Holidays are : \n" names<- getLocalNames conn False - print $ show names + putStrLn $ unlines names _ -> syntaxErrorForIsGlobal - putStrLn "\n****************" - putStrLn $ "Number of rows in Table is " ++ show (length res) - putStrLn "\n****************" - -- | JSON Conversion code is below + putStrLn $ "\nPreparing to write into the JSON file " + putStrLn "\nWriting ..." jsonValue <- convertToJSON conn - print $ show jsonValue - -- | JSON Conversion -> writing into file should be added below writeFile "DB.json" (jsonValue) - print "Done!" - putStrLn "\n****************" + putStrLn "\nFinished Writing!" syntaxErrorForIsGlobal :: IO () diff --git a/src/Database.hs b/src/Database.hs index 5d0aea9..268a974 100644 --- a/src/Database.hs +++ b/src/Database.hs @@ -65,7 +65,6 @@ insertDB :: Connection -> [HolidayRecord] -> IO () insertDB conn records = do let xs = records stmt <- prepare conn "INSERT INTO holidays (date,localName,name) VALUES (?,?,?)" -- this fuction use to insert the values into the parameters under the holidays table - putStrLn "Adding" -- this fuction to Type for s string with newline character at the end executeMany stmt (map (\x -> [toSql (date x), toSql (localName x), toSql (name x)]) xs) -- this function use for prepares a database operation and executes it against the parameters sequences commit conn -- this fuction to commit a transaction to the underlying database @@ -74,7 +73,6 @@ insertLB :: Connection -> [HolidayRecord] -> IO () insertLB conn records = do let xs = records stmt <- prepare conn "INSERT INTO countries (countryCode,global,fixed) VALUES (?,?,?)" -- this fuction use to insert the values into the parameters under the country table - putStrLn "Adding" -- this fuction to Type for s string with newline character at the end executeMany stmt (map (\x -> [toSql (countryCode x), toSql (global x), toSql (fixed x)]) xs) -- this function use for prepares a database operation and executes it against the parameters sequences commit conn -- this fuction to commit a transaction to the underlying database @@ -83,9 +81,8 @@ insertSB :: Connection -> [HolidayRecord] -> IO () insertSB conn records = do let xs = records stmt <- prepare conn "INSERT INTO country_holidays (countryCode,localName) VALUES (?,?)" -- this fuction use to insert the values into the parameters under the country_holidays - putStrLn "Adding" -- this fuction to Type for s string with newline character at the end executeMany stmt (map (\x -> [toSql (countryCode x), toSql (localName x)]) xs) -- this function use for prepares a database operation and executes it against the parameters sequences - commit conn -- this fuction to commit a transaction to the underlying database + commit conn -- this function to commit a transaction to the underlying database -- | This function will select all the holidays of a given country queryDB :: Connection -> String -> IO [[SqlValue]] diff --git a/src/Http.hs b/src/Http.hs index a6e29de..54d9096 100644 --- a/src/Http.hs +++ b/src/Http.hs @@ -1,4 +1,4 @@ --- |HTTP module header +-- | HTTP module header module Http ( download ) where @@ -6,7 +6,7 @@ module Http import qualified Data.ByteString.Lazy.Char8 as L8 import Network.HTTP.Simple ( parseRequest, getResponseBody, httpLBS ) --- |Download function is for converting JSON from URL +-- | This function is for converting JSON from URL download :: String -> IO L8.ByteString download url = do request <- parseRequest url diff --git a/src/Parse.hs b/src/Parse.hs index 87ea699..aa3731a 100644 --- a/src/Parse.hs +++ b/src/Parse.hs @@ -18,7 +18,7 @@ import GHC.Generics (Generic) -- } -- ] --- |HolidayRecord +-- |HolidayRecord constructor data HolidayRecord = HolidayRecord { date :: String, localName :: String, @@ -32,6 +32,6 @@ data HolidayRecord = HolidayRecord instance FromJSON HolidayRecord instance ToJSON HolidayRecord --- |Parse function for converting JSON to text +-- | This function is for converting JSON to text parse :: L8.ByteString -> Either String [HolidayRecord] parse json = eitherDecode json :: Either String [HolidayRecord]