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.

require 'rss/1.0'
require 'rss/2.0'
require 'open-uri'

def snarl(title, msg)
  # This part actually sends the notification.
  # Change "snarl" to your snarl command line tool if you have problems
  system "snarl /M \"#{title}\" \"#{msg}\""
end

source = ARGV[0]
content = ''
open(source) { |s| content = s.read }
rss = RSS::Parser.parse(content, false)
puts rss.channel.title
puts rss.channel.link
puts rss.channel.description

last_item = nil

while true
  puts "Checking for updates..."
  open(source) { |s| content = s.read }
  rss = RSS::Parser.parse(content, false)
  if last_item == rss.items[0]
    sleep 5*60*1000
  else
    last_item = rss.items[0]
    snarl last_item.title + " (#{rss.channel.title})", last_item.description.gsub(/<\/?[^>]*>/, "")
    sleep 10*60*1000
  end
end
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS