Skip to content

Instantly share code, notes, and snippets.

@LeipeLeon
Created January 27, 2009 15:31
Show Gist options
  • Save LeipeLeon/53381 to your computer and use it in GitHub Desktop.
Save LeipeLeon/53381 to your computer and use it in GitHub Desktop.
Send a growl message with latest updates in your wakoopa feed
#!/usr/bin/env ruby
#
# Send a growl message with latest updates in your feed
#
# edit your crontab (crontab -e) and add this line
# (this checks your feed every 30 minutes)
# */30 * * * * ~/bin/WakoopaGrowl.rb > /dev/null
#
# create a yaml file (mate ~/.wakoopa_growl) within your homedirectory
# username: your_username
require 'yaml'
prefs = File.expand_path('~/.wakoopa_growl')
begin
@wakoopa_config = YAML.load_file(prefs)
rescue Errno::ENOENT
raise "No such file! (#{prefs})"
end
if @wakoopa_config['username']
@username = @wakoopa_config['username']
else
raise "Provide a username in the config file (#{prefs}): username: username"
end
def growl(msg, img = nil)
title = 'Wakoopa New Software'
msg = "You started using #{msg}"
img ||= "/Applications/Wakoopa\ Tracker.app/Contents/Resources/icon.icns"
cmd = "/usr/local/bin/growlnotify -n wakoopa --image \"#{img}\" -m #{msg.inspect} \"#{title}\" "#{}"--udp --host localhost"
system `#{cmd}`
end
require 'rss'
# What feed are we parsing?
rss_feed = "http://wakoopa.com/" + @username + "/feed/"
# check latest update
from_date = @wakoopa_config['last_date'] || Time.at(0)
# Variable for storing feed content
rss_content = ""
# Read the feed into rss_content
open(rss_feed) do |f|
rss_content = f.read
end
# Parse the feed, dumping its contents to rss
rss = RSS::Parser.parse(rss_content, false)
rss.items.reverse.each { |item|
distance = from_date.utc.to_i - item.pubDate.utc.to_i
if distance < 0
growl(item.title.strip)
end
@wakoopa_config['last_date'] = item.pubDate.utc
}
# write lastdate back to file
File.open(prefs, 'w') { |f| f.puts @wakoopa_config.to_yaml }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment