Last active
December 19, 2015 17:19
-
-
Save lamixer/5990130 to your computer and use it in GitHub Desktop.
Attempt to allow Huginn to pull Wunderground data for City Country instead of zipcode. agents.yml is huginn/spec/fixtures/agents.yml. Line 72 of the modified agent is suspect - what is syntax for specifying multiple options in forecast_for?
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
jane_website_agent: | |
type: Agents::WebsiteAgent | |
user: jane | |
schedule: "5pm" | |
name: "ZKCD" | |
options: <%= { | |
:url => "http://trailers.apple.com/trailers/home/rss/newtrailers.rss", | |
:expected_update_period_in_days => 2, | |
:mode => :on_change, | |
:extract => { | |
:title => {:css => "item title", :text => true}, | |
:url => {:css => "item link", :text => true} | |
} | |
}.to_yaml.inspect %> | |
bob_website_agent: | |
type: Agents::WebsiteAgent | |
user: bob | |
schedule: "midnight" | |
name: "ZKCD" | |
options: <%= { | |
:url => "http://xkcd.com", | |
:expected_update_period_in_days => 2, | |
:mode => :on_change, | |
:extract => { | |
:url => {:css => "#comic img", :attr => "src"}, | |
:title => {:css => "#comic img", :attr => "title"} | |
} | |
}.to_yaml.inspect %> | |
bob_weather_agent: | |
type: Agents::WeatherAgent | |
user: bob | |
schedule: "midnight" | |
name: "SF Weather" | |
options: <%= { | |
:country => "UK", | |
:city => "London", | |
:zipcode => 94102, | |
:lat => 37.779329, | |
:lng => -122.41915, | |
:api_key => 'test' | |
}.to_yaml.inspect %> | |
jane_weather_agent: | |
type: Agents::WeatherAgent | |
user: jane | |
schedule: "midnight" | |
name: "SF Weather" | |
options: <%= { | |
:country => "UK", | |
:city => "London", | |
:zipcode => 94103, | |
:lat => 37.779329, | |
:lng => -122.41915, | |
:api_key => 'test' | |
}.to_yaml.inspect %> | |
jane_rain_notifier_agent: | |
type: Agents::TriggerAgent | |
user: jane | |
name: "Jane's Rain Watcher" | |
options: <%= { | |
:expected_receive_period_in_days => "2", | |
:rules => [{ | |
:type => "regex", | |
:value => "rain", | |
:path => "conditions" | |
}], | |
:message => "Just so you know, it looks like '<conditions>' tomorrow in '<city>', '<country>'." | |
}.to_yaml.inspect %> | |
bob_rain_notifier_agent: | |
type: Agents::TriggerAgent | |
user: bob | |
name: "Bob's Rain Watcher" | |
options: <%= { | |
:expected_receive_period_in_days => "2", | |
:rules => [{ | |
:type => "regex", | |
:value => "rain", | |
:path => "conditions" | |
}], | |
:message => "Just so you know, it looks like '<conditions>' tomorrow in '<city>', '<country>'." | |
}.to_yaml.inspect %> | |
bob_twitter_user_agent: | |
type: Agents::TwitterUserAgent | |
user: bob | |
name: "Bob's Twitter User Watcher" | |
options: <%= { | |
:username => "tectonic", | |
:expected_update_period_in_days => "2", | |
:consumer_key => "---", | |
:consumer_secret => "---", | |
:oauth_token => "---", | |
:oauth_token_secret => "---" | |
}.to_yaml.inspect %> |
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
require 'date' | |
module Agents | |
class WeatherAgent < Agent | |
cannot_receive_events! | |
description <<-MD | |
The WeatherAgent creates an event for the following day's weather in `city`, `country`. | |
You must setup an [API key for Wunderground](http://www.wunderground.com/weather/api/) in order to use this Agent. | |
MD | |
event_description <<-MD | |
Events look like this: | |
{ | |
:country => "UK", | |
:city => "London", | |
:date => { :epoch=>"1357959600", :pretty=>"10:00 PM EST on January 11, 2013" }, | |
:high => { :fahrenheit=>"64", :celsius=>"18" }, | |
:low => { :fahrenheit=>"52", :celsius=>"11" }, | |
:conditions => "Rain Showers", | |
:icon=>"rain", | |
:icon_url => "http://icons-ak.wxug.com/i/c/k/rain.gif", | |
:skyicon => "mostlycloudy", | |
:pop => 80, | |
:qpf_allday => { :in=>0.24, :mm=>6.1 }, | |
:qpf_day => { :in=>0.13, :mm=>3.3 }, | |
:qpf_night => { :in=>0.03, :mm=>0.8 }, | |
:snow_allday => { :in=>0, :cm=>0 }, | |
:snow_day => { :in=>0, :cm=>0 }, | |
:snow_night => { :in=>0, :cm=>0 }, | |
:maxwind => { :mph=>15, :kph=>24, :dir=>"SSE", :degrees=>160 }, | |
:avewind => { :mph=>9, :kph=>14, :dir=>"SSW", :degrees=>194 }, | |
:avehumidity => 85, | |
:maxhumidity => 93, | |
:minhumidity => 63 | |
} | |
MD | |
default_schedule "8pm" | |
def working? | |
(event = event_created_within(2.days)) && event.payload.present? | |
end | |
def wunderground | |
Wunderground.new(options[:api_key]) if key_setup? | |
end | |
def key_setup? | |
options[:api_key] && options[:api_key] != "your-key" | |
end | |
def default_options | |
{ | |
:api_key => "your-key", | |
:country => "UK", | |
:city => "London" | |
} | |
end | |
def validate_options | |
errors.add(:base, "country is required") unless options[:country].present? | |
errors.add(:base, "city is required") unless options[:city].present? | |
errors.add(:base, "api_key is required") unless options[:api_key].present? | |
end | |
def check | |
if key_setup? | |
wunderground.forecast_for(options[:country][:city])["forecast"]["simpleforecast"]["forecastday"].each do |day| | |
if is_tomorrow?(day) | |
create_event :payload => day.merge(:city => options[:city]) | |
end | |
end | |
end | |
end | |
def is_tomorrow?(day) | |
Time.zone.at(day["date"]["epoch"].to_i).to_date == Time.zone.now.tomorrow.to_date | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment