@@ -82,22 +82,22 @@ module Agents |
||
| 82 | 82 |
end |
| 83 | 83 |
|
| 84 | 84 |
def wunderground |
| 85 |
- data = Wunderground.new(options['api_key']).forecast_for(options['location'])['forecast']['simpleforecast']['forecastday'] if key_setup? |
|
| 86 |
- return data |
|
| 85 |
+ Wunderground.new(options['api_key']).forecast_for(options['location'])['forecast']['simpleforecast']['forecastday'] if key_setup? |
|
| 87 | 86 |
end |
| 88 | 87 |
|
| 89 | 88 |
def forecastio |
| 90 |
- ForecastIO.api_key = options['api_key'] if key_setup? |
|
| 91 |
- data = ForecastIO.forecast(options['location'].split(',')[0], options['location'].split(',')[1])['daily']['data']
|
|
| 92 |
- return data |
|
| 89 |
+ if key_setup? |
|
| 90 |
+ ForecastIO.api_key = options['api_key'] |
|
| 91 |
+ lat, lng = options['location'].split(',')
|
|
| 92 |
+ ForecastIO.forecast(lat,lng)['daily']['data'] |
|
| 93 |
+ end |
|
| 93 | 94 |
end |
| 94 | 95 |
|
| 95 |
- def model(data,service,which_day) |
|
| 96 |
- day = Hash.new |
|
| 96 |
+ def model(service,which_day) |
|
| 97 | 97 |
if service == "wunderground" |
| 98 |
- day = data[which_day] |
|
| 98 |
+ wunderground[which_day] |
|
| 99 | 99 |
elsif service == "forecastio" |
| 100 |
- data.each do |value| |
|
| 100 |
+ forecastio.each do |value| |
|
| 101 | 101 |
timestamp = Time.at(value.time) |
| 102 | 102 |
if (timestamp.to_date - Time.now.to_date).to_i == which_day |
| 103 | 103 |
day = {
|
@@ -158,20 +158,15 @@ module Agents |
||
| 158 | 158 |
'pressure' => value.pressure.to_s, |
| 159 | 159 |
'ozone' => value.ozone.to_s |
| 160 | 160 |
} |
| 161 |
- end |
|
| 162 |
- end |
|
| 161 |
+ return day |
|
| 162 |
+ end |
|
| 163 |
+ end |
|
| 163 | 164 |
end |
| 164 |
- return day.merge('location' => options['location'])
|
|
| 165 | 165 |
end |
| 166 | 166 |
|
| 167 | 167 |
def check |
| 168 | 168 |
if key_setup? |
| 169 |
- if service == 'forecastio' |
|
| 170 |
- weather = model(forecastio, service, which_day) |
|
| 171 |
- elsif service == 'wunderground' |
|
| 172 |
- weather = model(wunderground, service, which_day) |
|
| 173 |
- end |
|
| 174 |
- create_event :payload => weather |
|
| 169 |
+ create_event :payload => model(service, which_day).merge('location' => options['location'])
|
|
| 175 | 170 |
end |
| 176 | 171 |
end |
| 177 | 172 |
|