<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: Zuwiki's Code Snippets</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 05 Sep 2008 08:16:54 GMT</pubDate>
    <description>DZone Snippets: Zuwiki's Code Snippets</description>
    <item>
      <title>Simple Ruby Snarl RSS alerter</title>
      <link>http://snippets.dzone.com/posts/show/5092</link>
      <description>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.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;require 'rss/1.0'&lt;br /&gt;require 'rss/2.0'&lt;br /&gt;require 'open-uri'&lt;br /&gt;&lt;br /&gt;def snarl(title, msg)&lt;br /&gt;  # This part actually sends the notification.&lt;br /&gt;  # Change "snarl" to your snarl command line tool if you have problems&lt;br /&gt;  system "snarl /M \"#{title}\" \"#{msg}\""&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;source = ARGV[0]&lt;br /&gt;content = ''&lt;br /&gt;open(source) { |s| content = s.read }&lt;br /&gt;rss = RSS::Parser.parse(content, false)&lt;br /&gt;puts rss.channel.title&lt;br /&gt;puts rss.channel.link&lt;br /&gt;puts rss.channel.description&lt;br /&gt;&lt;br /&gt;last_item = nil&lt;br /&gt;&lt;br /&gt;while true&lt;br /&gt;  puts "Checking for updates..."&lt;br /&gt;  open(source) { |s| content = s.read }&lt;br /&gt;  rss = RSS::Parser.parse(content, false)&lt;br /&gt;  if last_item == rss.items[0]&lt;br /&gt;    sleep 5*60*1000&lt;br /&gt;  else&lt;br /&gt;    last_item = rss.items[0]&lt;br /&gt;    snarl last_item.title + " (#{rss.channel.title})", last_item.description.gsub(/&lt;\/?[^&gt;]*&gt;/, "")&lt;br /&gt;    sleep 10*60*1000&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 02 Feb 2008 23:02:17 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5092</guid>
      <author>zuwiki (Mike Zink)</author>
    </item>
  </channel>
</rss>
