Skip to content

Commit

Permalink
Update forecast_io gem and language (huginn#1722)
Browse files Browse the repository at this point in the history
  • Loading branch information
cantino authored Oct 9, 2016
1 parent 3d70908 commit 005be58
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
8 changes: 4 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ GEM
oauth (>= 0.4.1)
execjs (2.6.0)
extlib (0.9.16)
faraday (0.9.1)
faraday (0.9.2)
multipart-post (>= 1.2, < 3)
feedjira (2.0.0)
faraday (~> 0.9)
Expand All @@ -222,7 +222,7 @@ GEM
ffi (1.9.10)
font-awesome-sass (4.3.2.1)
sass (~> 3.2)
forecast_io (2.0.0)
forecast_io (2.0.1)
faraday
hashie
multi_json
Expand Down Expand Up @@ -267,7 +267,7 @@ GEM
guard (~> 2.1)
guard-compat (~> 1.1)
rspec (>= 2.99.0, < 4.0)
hashie (3.4.4)
hashie (3.4.6)
haversine (0.3.0)
hipchat (1.2.0)
httparty
Expand Down Expand Up @@ -705,4 +705,4 @@ RUBY VERSION
ruby 2.3.1p112

BUNDLED WITH
1.12.5
1.13.2
17 changes: 9 additions & 8 deletions app/models/agents/weather_agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ class WeatherAgent < Agent
You also must select `which_day` you would like to get the weather for where the number 0 is for today and 1 is for tomorrow and so on. Weather is only returned for 1 week at a time.
The weather can be provided by either Wunderground or ForecastIO. To choose which `service` to use, enter either `forecastio` or `wunderground`.
The weather can be provided by either Wunderground or Dark Sky. To choose which `service` to use, enter either `darksky` or `wunderground`.
The `location` can be a US zipcode, or any location that Wunderground supports. To find one, search [wunderground.com](http://wunderground.com) and copy the location part of the URL. For example, a result for San Francisco gives `http://www.wunderground.com/US/CA/San_Francisco.html` and London, England gives `http://www.wunderground.com/q/zmw:00000.1.03772`. The locations in each are `US/CA/San_Francisco` and `zmw:00000.1.03772`, respectively.
The `location` should be:
If you plan on using ForecastIO, the `location` must be a comma-separated string of co-ordinates (longitude, latitude). For example, San Francisco would be `37.7771,-122.4196`.
* For Wunderground: A US zipcode, or any location that Wunderground supports. To find one, search [wunderground.com](http://wunderground.com) and copy the location part of the URL. For example, a result for San Francisco gives `http://www.wunderground.com/US/CA/San_Francisco.html` and London, England gives `http://www.wunderground.com/q/zmw:00000.1.03772`. The locations in each are `US/CA/San_Francisco` and `zmw:00000.1.03772`, respectively.
* For Dark Sky: `location` must be a comma-separated string of co-ordinates (longitude, latitude). For example, San Francisco would be `37.7771,-122.4196`.
You must setup an [API key for Wunderground](http://www.wunderground.com/weather/api/) in order to use this Agent with Wunderground.
You must setup an [API key for Forecast](https://developer.forecast.io/) in order to use this Agent with ForecastIO.
You must setup an [API key for Dark Sky](https://darksky.net/dev/) in order to use this Agent with Dark Sky.
Set `expected_update_period_in_days` to the maximum amount of time that you'd expect to pass between Events being created by this Agent.
Expand Down Expand Up @@ -100,7 +101,7 @@ def language
end

def validate_options
errors.add(:base, "service must be set to 'forecastio' or 'wunderground'") unless ["forecastio", "wunderground"].include?(weather_provider)
errors.add(:base, "service must be set to 'darksky' or 'wunderground'") unless %w[darksky forecastio wunderground].include?(weather_provider)
errors.add(:base, "location is required") unless location.present?
errors.add(:base, "api_key is required") unless interpolated['api_key'].present?
errors.add(:base, "which_day selection is required") unless which_day.present?
Expand All @@ -116,7 +117,7 @@ def wunderground
end
end

def forecastio
def dark_sky
if key_setup?
ForecastIO.api_key = interpolated['api_key']
lat, lng = location.split(',')
Expand All @@ -127,8 +128,8 @@ def forecastio
def model(weather_provider,which_day)
if weather_provider == "wunderground"
wunderground[which_day]
elsif weather_provider == "forecastio"
forecastio.each do |value|
elsif weather_provider == "darksky" || weather_provider == "forecastio"
dark_sky.each do |value|
timestamp = Time.at(value.time)
if (timestamp.to_date - Time.now.to_date).to_i == which_day
day = {
Expand Down

0 comments on commit 005be58

Please sign in to comment.