Created
March 14, 2011 23:59
-
-
Save jhawthorn/870101 to your computer and use it in GitHub Desktop.
alarm which rings until your google reader entries are all read
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
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