Skip to content

Instantly share code, notes, and snippets.

@digideskio
Forked from tachyons/cricinfo
Created November 5, 2015 00:11
Show Gist options
  • Save digideskio/112f33e10a83b261a512 to your computer and use it in GitHub Desktop.
Save digideskio/112f33e10a83b261a512 to your computer and use it in GitHub Desktop.
cricinfo status in your desktop
#!/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