#!/usr/bin/ruby1.8
require 'cgi'
require 'nkf'
require 'rss/maker'
require 'time'
require 'uri'
title = 'Ruby hotlinks: '
description = 'Ruby hotlinks: powered by samidare'
link_uri = URI.parse('http://www.rubyist.net/~kazu/samidare/latest')
now = Time.now
threshold = 60*60*24*7 # 1week
links = Hash.new {|h,k| h[k] = [] }
category = nil
ARGF.read.scan(/^(?:>([\d\-:A-Z ]+)<\/a
>&\#32;C<\/a
> ([^<>]+)<\/a|> threshold
links[category].push h
end
links.each do |k, v|
links[k] = v.sort_by {|h| -h[:time].to_i}
end
links.keys.each do |k|
filename = k.gsub(/[^A-Za-z0-9\-]+/, '') + '.rdf'
rss = RSS::Maker.make('1.0') do |maker|
maker.channel.about = link_uri + filename
maker.channel.title = title + k
maker.channel.description = description
maker.channel.link = link_uri
links[k].each do |h|
item = maker.items.new_item
item.link = h[:link]
#item.link = h[:link_with_time]
item.title = h[:title]
item.date = h[:time]
item.content_encoded = '%1$s' % [h[:link]]
end
end
File.open(filename, "wb") do |f|
f.puts rss
end
end