Skip to content

Instantly share code, notes, and snippets.

@burke
Created August 31, 2009 21:46
Show Gist options
  • Save burke/178732 to your computer and use it in GitHub Desktop.
Save burke/178732 to your computer and use it in GitHub Desktop.
begin
require 'rubygems'
rescue LoadError;end
%w{net/http uri nokogiri ruby-growl yaml prowl}.each{|e|require e}
class EveNotifier
GROWL = {
:host => "espresso.h",
:password => "tr32"
}
APIHOST = "http://api.eve-online.com"
APIINFO = YAML.load_file('api-info.yml')
def get_balance
params = {
'characterID' => APIINFO['characterID'],
'userID' => APIINFO['userID'],
'apiKey' => APIINFO['apiKey']
}
res = Net::HTTP.post_form(URI.parse("#{APIHOST}/char/AccountBalance.xml.aspx"), params)
doc = Nokogiri::XML(res.body)
doc.xpath('//row').first.attributes['balance'].to_s.to_i
end
def send(type,title,message)
begin
g = Growl.new(GROWL[:host], "EVE Online", ["Balance Change"], nil, GROWL[:password])
g.notify(type, title, message, 0, true)
rescue SocketError
begin
Prowl.add(APIINFO['prowlApiKey'], :application => "EVE", :event => title, :description => message)
rescue SocketError; end
end
end
def run
old_balance = balance = get_balance
loop do
old_balance = balance
balance = get_balance
if balance != old_balance
diff = balance - old_balance
message = "Balance #{diff>0 ? 'increased' : 'decreased'} by #{diff.abs} to #{balance}"
send("Balance Change", "Balance Changed", message)
end
puts "balance: #{balance}"
sleep 60
end
end
end
if __FILE__ == $0
EveNotifier.new.run
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment