Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Mike Zink http://log.zuwiki.net

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Simple Ruby Snarl RSS alerter

This simple Ruby program will send a Snarl alert when a new post is added to a feed. Assumes your Snarl command line tool is named "snarl.exe" and in your PATH.

   1  
   2  require 'rss/1.0'
   3  require 'rss/2.0'
   4  require 'open-uri'
   5  
   6  def snarl(title, msg)
   7    # This part actually sends the notification.
   8    # Change "snarl" to your snarl command line tool if you have problems
   9    system "snarl /M \"#{title}\" \"#{msg}\""
  10  end
  11  
  12  source = ARGV[0]
  13  content = ''
  14  open(source) { |s| content = s.read }
  15  rss = RSS::Parser.parse(content, false)
  16  puts rss.channel.title
  17  puts rss.channel.link
  18  puts rss.channel.description
  19  
  20  last_item = nil
  21  
  22  while true
  23    puts "Checking for updates..."
  24    open(source) { |s| content = s.read }
  25    rss = RSS::Parser.parse(content, false)
  26    if last_item == rss.items[0]
  27      sleep 5*60*1000
  28    else
  29      last_item = rss.items[0]
  30      snarl last_item.title + " (#{rss.channel.title})", last_item.description.gsub(/<\/?[^>]*>/, "")
  31      sleep 10*60*1000
  32    end
  33  end
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS