Skip to content

Instantly share code, notes, and snippets.

@madflow
Created January 5, 2014 19:58
Show Gist options
  • Save madflow/8272994 to your computer and use it in GitHub Desktop.
Save madflow/8272994 to your computer and use it in GitHub Desktop.
TvRage Agent for huginn
require 'nokogiri'
require 'typhoeus'
require 'date'
module Agents
class TvrageAgent < Agent
cannot_receive_events!
def working?
!recent_error_logs?
end
@@info_url = 'http://services.tvrage.com/feeds/full_show_info.php?sid=%{sid}'
description <<-MD
# TvrageAgent
The configuration expects a collection of show ids.
http://services.tvrage.com/feeds/search.php?show=SHOWNAME
MD
default_schedule "every_1d"
def default_options
{
:shows => [],
:format => 'text'
}
end
def check
result = {}
hydra = Typhoeus::Hydra.new
options[:shows].each do |sid|
doc = {}
log "Fetching show"
url = @@info_url % {sid:sid.to_i}
request = Typhoeus::Request.new(url)
request.on_failure do |response|
error "Failed: #{response.inspect}"
end
request.on_success do |response|
log "Parse response"
doc = parse(response.body)
result = doc
end
end
create_event :payload => result
end
def parse(data)
Nokogiri::XML(response.body)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment