Created
November 21, 2009 12:32
-
-
Save pilotmoon/240112 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/ruby | |
# Log in to Red Hot Pawn, check if there are games waiting, and print a message | |
# indicating the result. | |
require 'net/http' | |
require 'uri' | |
MAIL='you@example.com' | |
PASS='password' | |
QUERY_URL=URI::parse('http://www.redhotpawn.com/xml/xstatus/gameswaitingxml.php') | |
begin | |
# log in and get cookies | |
response=Net::HTTP.post_form(QUERY_URL, {'loginemail'=>MAIL, 'loginpassword'=>PASS}) | |
raise "HTTP response code #{response.code}" if response.code != "200" | |
# demonstrate once logged in | |
# parse cookies and build cookie string for request. | |
# this is a bit quick and dirty, it picks out cookies with names | |
# beginning 'rhp_'. it might break if RHP change something. | |
#cookies=response['set-cookie'].scan(/rhp_.+?=.+?;/).join(' ') | |
# get games waiting | |
#response=Net::HTTP.start(QUERY_URL.host) do |http| | |
# http.get(QUERY_URL.path, {'cookie' => cookies}) | |
#end | |
count=response.body.match(/<gameswaiting>(.+?)<\/gameswaiting>/)[1].to_i | |
puts "#{count} games waiting" | |
rescue | |
puts "Script failed: #{$!}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment