Compare commits
No commits in common. "16981d9d3fe13442b2de38fc308567dad1caf520" and "c388f4c7a5cba02cf32511564f6ef2bb4ce72c46" have entirely different histories.
16981d9d3f
...
c388f4c7a5
@ -64,18 +64,3 @@ weatherDecode jsonBody =
|
|||||||
case decode jsonBody :: Maybe WeatherResponse of
|
case decode jsonBody :: Maybe WeatherResponse of
|
||||||
Just decoded -> return decoded
|
Just decoded -> return decoded
|
||||||
Nothing -> error "Invalid JSON"
|
Nothing -> error "Invalid JSON"
|
||||||
|
|
||||||
getTemperature :: WeatherResponse -> Float
|
|
||||||
getTemperature (WeatherResponse _ Nothing Nothing) = error "No data provided!"
|
|
||||||
getTemperature (WeatherResponse _ (Just curr) Nothing) = getTemperatureFromCurrent curr
|
|
||||||
getTemperature (WeatherResponse _ Nothing (Just fore)) = getTemperatureFromForecastDay $ getForecastDayFromForecast fore
|
|
||||||
getTemperature (WeatherResponse _ (Just _) (Just fore)) = getTemperatureFromForecastDay $ getForecastDayFromForecast fore
|
|
||||||
|
|
||||||
getForecastDayFromForecast :: Forecast -> ForecastDay
|
|
||||||
getForecastDayFromForecast (Forecast forecasts) = head forecasts
|
|
||||||
|
|
||||||
getTemperatureFromCurrent :: Current -> Float
|
|
||||||
getTemperatureFromCurrent (Current temp) = temp
|
|
||||||
|
|
||||||
getTemperatureFromForecastDay :: ForecastDay -> Float
|
|
||||||
getTemperatureFromForecastDay (ForecastDay (Day temp)) = temp
|
|
10
app/Main.hs
10
app/Main.hs
@ -7,6 +7,7 @@ import Data.Time as T
|
|||||||
import Plot
|
import Plot
|
||||||
import qualified DataTypes as DT
|
import qualified DataTypes as DT
|
||||||
|
|
||||||
|
|
||||||
data WhichDay = Yesterday | Today | Tomorrow
|
data WhichDay = Yesterday | Today | Tomorrow
|
||||||
deriving (Show, Eq)
|
deriving (Show, Eq)
|
||||||
|
|
||||||
@ -33,22 +34,25 @@ main = do
|
|||||||
let yesterdayDate = formatDate $ addDays (-1) currentDate
|
let yesterdayDate = formatDate $ addDays (-1) currentDate
|
||||||
let yesterdayRequest = apiRequestBuilder apiKey Yesterday city yesterdayDate
|
let yesterdayRequest = apiRequestBuilder apiKey Yesterday city yesterdayDate
|
||||||
yesterdayResponse <- httpLBS yesterdayRequest
|
yesterdayResponse <- httpLBS yesterdayRequest
|
||||||
|
print $ getResponseStatusCode yesterdayResponse
|
||||||
yesterdayDecoded <- DT.weatherDecode $ getResponseBody yesterdayResponse
|
yesterdayDecoded <- DT.weatherDecode $ getResponseBody yesterdayResponse
|
||||||
print ("Yesterday's temperature: ", DT.getTemperature yesterdayDecoded)
|
print yesterdayDecoded
|
||||||
|
|
||||||
--request for today's weather
|
--request for today's weather
|
||||||
let todayDate = formatDate currentDate
|
let todayDate = formatDate currentDate
|
||||||
let todayRequest = apiRequestBuilder apiKey Today city todayDate
|
let todayRequest = apiRequestBuilder apiKey Today city todayDate
|
||||||
todayResponse <- httpLBS todayRequest
|
todayResponse <- httpLBS todayRequest
|
||||||
|
print $ getResponseStatusCode todayResponse
|
||||||
todayDecoded <- DT.weatherDecode $ getResponseBody todayResponse
|
todayDecoded <- DT.weatherDecode $ getResponseBody todayResponse
|
||||||
print ("Today's temperature: ", DT.getTemperature todayDecoded)
|
print todayDecoded
|
||||||
|
|
||||||
--request for tomorrow's weather
|
--request for tomorrow's weather
|
||||||
let tomorrowDate = formatDate $ addDays 1 currentDate
|
let tomorrowDate = formatDate $ addDays 1 currentDate
|
||||||
let tomorrowRequest = apiRequestBuilder apiKey Tomorrow city tomorrowDate
|
let tomorrowRequest = apiRequestBuilder apiKey Tomorrow city tomorrowDate
|
||||||
tomorrowResponse <- httpLBS tomorrowRequest
|
tomorrowResponse <- httpLBS tomorrowRequest
|
||||||
|
print $ getResponseStatusCode tomorrowResponse
|
||||||
tomorrowDecoded <- DT.weatherDecode $ getResponseBody tomorrowResponse
|
tomorrowDecoded <- DT.weatherDecode $ getResponseBody tomorrowResponse
|
||||||
print ("Tomorrow's temperature: ", DT.getTemperature tomorrowDecoded)
|
print tomorrowDecoded
|
||||||
|
|
||||||
|
|
||||||
--apiKey is stored in an env variable, not something that should be pushed onto git
|
--apiKey is stored in an env variable, not something that should be pushed onto git
|
||||||
|
Loading…
Reference in New Issue
Block a user