Skip to content

Instantly share code, notes, and snippets.

@sbastn
Created December 24, 2016 09:15
Show Gist options
  • Save sbastn/ea98bf9bbcda5f7c89b0a7565570c043 to your computer and use it in GitHub Desktop.
Save sbastn/ea98bf9bbcda5f7c89b0a7565570c043 to your computer and use it in GitHub Desktop.
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
@sbastn
Copy link
Author

sbastn commented Dec 24, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment