Created
December 24, 2016 09:15
-
-
Save sbastn/ea98bf9bbcda5f7c89b0a7565570c043 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
get '/run/:location' do |location| | |
geocoder = Geocoder.search(location) | |
unless geocoder.empty? | |
latitude = geocoder.first.data['geometry']['location']['lat'] | |
longitude = geocoder.first.data['geometry']['location']['lng'] | |
forecast = Forecast::IO.forecast(latitude, longitude) | |
@location = geocoder.first.data['formatted_address'] | |
tz = TZInfo::Timezone.get(forecast.timezone) | |
next_hours = forecast.hourly.data.first(7).each_with_index.map do |data, index| | |
{ | |
time: Time.at(tz.now + (60 * 60 * index)), | |
icon: data.icon, | |
condition: data.summary, | |
temperature: to_celsius(data.temperature), | |
} | |
end | |
@theme = next_hours.first[:icon] | |
@condition = next_hours.first[:condition] | |
@action, @message = running_conditions(next_hours) | |
@current_time = Time.at(tz.now) | |
@temperature = next_hours.first[:temperature] | |
@runner = determineRunner(@action, @temperature) | |
haml :run, layout: :run_layout | |
else | |
@location_not_found = location | |
haml :run_intro, layout: :run_layout | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For @Kikobeats