Skip to content

Instantly share code, notes, and snippets.

@jhawthorn
Created March 14, 2011 23:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhawthorn/870101 to your computer and use it in GitHub Desktop.
Save jhawthorn/870101 to your computer and use it in GitHub Desktop.
alarm which rings until your google reader entries are all read
require 'rubygems'
require 'net/http'
require 'nokogiri'
require 'time'
Auth = 'YOUR AUTH KEY'
def unread_items
headers = {'Authorization' => "GoogleLogin auth=#{Auth}" }
http = Net::HTTP.new(host='www.google.com')
http.start
req = Net::HTTP::Get.new('/reader/api/0/unread-count?all=true', initheader = headers)
response = http.request(req)
doc = Nokogiri::XML(response.body)
objects = doc/'/object/list/object'
!objects.empty?
end
def timestr str
time = Time.parse(str)
if time < Time.now
time += 24 * 60 * 60
end
time
end
def alarm
pipe = IO.popen('mplayer -loop 0 ~/.alarm.wav')
$stdin.gets
Process.kill 'TERM', pipe.pid
pipe.close
end
alarmtime = timestr(ARGV[0])
sleep(alarmtime - Time.now)
puts
puts "Wake up!"
puts "ENTER TO PAUSE!"
puts
loop do
alarm
puts
puts "Alarm paused."
puts "Will ring again if news is not read"
puts
sleep 5
break unless unread_items
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment