#!/opt/local/bin/ruby
require 'md5'
require 'rss'
require 'open-uri'

class Site
  attr_accessor :url, :hash
  def initialize(url)
    url = "http://" + url unless url =~ /^http/
    @url = url
    @hash = MD5.new(@url)
    save
  end
  
  def save
    # To make this work on windows, replace these next to lines with:
    # %x{url2png.exe #{@url} #{File.join(Dir.pwd, @hash.to_s + "_t.png")}}
    # you can get url2png.exe from here: http://xoopscube.org/modules/xhnewbb/viewtopic.php?topic_id=331
    %x{osascript pap.scpt #{@url} #{@hash}}
    %x{convert #{@hash}.png -resize 200x #{@hash}_t.png}
    
    File.open("#{@hash}.url", "w") { |f| f.write @url }
  end
end

rss = RSS::Parser.parse(open("http://del.icio.us/rss/Xinex/greatdesign").read)
rss.items.each do |item|
  Site.new(item.link)
end