Skip to content

Instantly share code, notes, and snippets.

@msonnabaum
Created December 22, 2011 00:41
Show Gist options
  • Select an option

  • Save msonnabaum/1508392 to your computer and use it in GitHub Desktop.

Select an option

Save msonnabaum/1508392 to your computer and use it in GitHub Desktop.

Revisions

  1. msonnabaum revised this gist Dec 22, 2011. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion drupal_issue_notify.rb
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,6 @@
    require 'open-uri'
    require 'ruby_gntp'
    require 'tempfile'
    require 'optparse'

    def store_dump(filename, obj)
    marshal_dump = Marshal.dump(obj)
  2. msonnabaum created this gist Dec 22, 2011.
    75 changes: 75 additions & 0 deletions drupal_issue_notify.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,75 @@
    #!/usr/bin/env ruby
    require 'rubygems'
    require 'rss/1.0'
    require 'rss/2.0'
    require 'zlib'
    require 'open-uri'
    require 'ruby_gntp'
    require 'tempfile'
    require 'optparse'

    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)