Compare commits

..

No commits in common. "16981d9d3fe13442b2de38fc308567dad1caf520" and "c388f4c7a5cba02cf32511564f6ef2bb4ce72c46" have entirely different histories.

2 changed files with 7 additions and 18 deletions

View File

@ -64,18 +64,3 @@ weatherDecode jsonBody =
case decode jsonBody :: Maybe WeatherResponse of
Just decoded -> return decoded
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

View File

@ -7,6 +7,7 @@ import Data.Time as T
import Plot
import qualified DataTypes as DT
data WhichDay = Yesterday | Today | Tomorrow
deriving (Show, Eq)
@ -33,22 +34,25 @@ main = do
let yesterdayDate = formatDate $ addDays (-1) currentDate
let yesterdayRequest = apiRequestBuilder apiKey Yesterday city yesterdayDate
yesterdayResponse <- httpLBS yesterdayRequest
print $ getResponseStatusCode yesterdayResponse
yesterdayDecoded <- DT.weatherDecode $ getResponseBody yesterdayResponse
print ("Yesterday's temperature: ", DT.getTemperature yesterdayDecoded)
print yesterdayDecoded
--request for today's weather
let todayDate = formatDate currentDate
let todayRequest = apiRequestBuilder apiKey Today city todayDate
todayResponse <- httpLBS todayRequest
print $ getResponseStatusCode todayResponse
todayDecoded <- DT.weatherDecode $ getResponseBody todayResponse
print ("Today's temperature: ", DT.getTemperature todayDecoded)
print todayDecoded
--request for tomorrow's weather
let tomorrowDate = formatDate $ addDays 1 currentDate
let tomorrowRequest = apiRequestBuilder apiKey Tomorrow city tomorrowDate
tomorrowResponse <- httpLBS tomorrowRequest
print $ getResponseStatusCode 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