Last active
November 8, 2015 20:07
-
-
Save tachyons/48a3655845b1a988aa91 to your computer and use it in GitHub Desktop.
cricinfo status in your desktop
This file contains hidden or 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/env ruby | |
require 'date' | |
require 'rubygems' | |
require 'libnotify' | |
require 'net/http' | |
require 'rexml/document' | |
require 'xmlsimple' | |
def every( time ) | |
Thread.new { | |
loop do | |
sleep(time) | |
yield | |
end | |
} | |
end | |
class Numeric | |
def seconds | |
self | |
end | |
def minutes | |
self * 60 | |
end | |
def hours | |
self * 60 * 60 | |
end | |
end | |
last_details="" | |
every( 30.seconds ) { | |
# fetch score | |
url = 'http://static.cricinfo.com/rss/livescores.xml' | |
# get the XML data as a string | |
xml_data = Net::HTTP.get_response(URI.parse(url)).body | |
data = XmlSimple.xml_in(xml_data) | |
details=data["channel"][0]["item"][0]["description"][0] | |
if details != last_details | |
Libnotify.show :summary => "Score", :body => details | |
end | |
last_details=details | |
} | |
# Do some other processing so it stays alive | |
sleep(10000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
install dependencies
Ruby 1.8.7
gem install xml-simple
gem install libnotify