Skip to content

Instantly share code, notes, and snippets.

@msonnabaum
Created December 22, 2011 00:41
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msonnabaum/1508392 to your computer and use it in GitHub Desktop.
Save msonnabaum/1508392 to your computer and use it in GitHub Desktop.
Script to notify you of new issues you're participating in via growl. Just pass it your drupal.org user id as the first arg.
#!/usr/bin/env ruby
require 'rubygems'
require 'rss/1.0'
require 'rss/2.0'
require 'zlib'
require 'open-uri'
require 'ruby_gntp'
require 'tempfile'
def store_dump(filename, obj)
marshal_dump = Marshal.dump(obj)
file = File.new(filename,'w')
file = Zlib::GzipWriter.new(file)
file.write marshal_dump
file.close
end
def load_dump(filename)
begin
file = Zlib::GzipReader.open(filename)
rescue Zlib::GzipFile::Error
file = File.open(filename, 'r')
ensure
obj = Marshal.load file.read
file.close
return obj
end
end
if ARGV.length > 0
begin
user_id = Integer(ARGV[0])
rescue ArgumentError
abort("Must provide a valid drupal.org username!")
end
end
feed = "http://drupal.org/project/issues/user/#{user_id}/feed"
rss = RSS::Parser.parse(open(feed))
filename = "#{Dir.tmpdir}/do-notify.marshal"
prev_rss = load_dump(filename) if FileTest.exists?(filename)
new = []
# Loop through the new feed items and compare them to what we have stored.
rss.items.each_with_index do |item, index|
is_new = true
unless prev_rss.nil?
prev_rss.items.each_with_index do |prev_item, i|
if prev_item.guid.content == item.guid.content
# If the guid is the same but the date is different, consider it new.
if prev_item.date.to_i == item.date.to_i
is_new = false
end
end
end
end
# If we haven't found a matching feed item in the stored feed, consider it new.
new << item if is_new
# Don't try to show more than 5 at a time.
break if index > 5
end
new.each do |n|
GNTP.notify({
:app_name => "D.O. Notify",
:title => "D.O. Notify",
:text => n.title,
:icon => "http://drupal.org/files/druplicon.small_.png",
:sticky => true,
})
end
store_dump(filename, rss)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment