#!/ruby/bin/ruby
require 'rss'
# RSSファイルのURL
url = "http://raa.ruby-lang.org/index.rdf"
content = ""
open( url ) do |s|
content = s.read
end
# RSSのパース
begin
rss = RSS::Parser.parse( content )
rescue RSS::InvalidRSSError
rss = RSS::Parser.parse( content, false )
end
# HTMLの出力開始
print "Content-type: text/html\n\n"
# channnelタグ出力
channel = rss.channel
printf("<html>\n<head>\n\t<title>RSS - %s</title>\n</head>\n<body>\n",
channel.title
)
printf( "<h3><a href=\"%s\">%s</a></h3>\n<p>%s</p>\n",
channel.link,
channel.title,
channel.description
)
# imageタグ出力
if rss.image != nil then
image = rss.image
printf( "<p><a href=\"%s\"><img src=\"%s\" alt=\"%s\" align=\"right\"></a></p>\n",
image.link,
image.url,
image.title
)
end
# itemタグ出力
print "<dl>\n"
rss.items.each do |i|
printf( "\t<dt><a href=\"%s\">%s</a></dt>\n\t<dd>%s</dd>\n",
i.link,
i.title,
i.description
)
end
print "</dl>\n"
# HTMLの出力終了
print "</body>\n</html>\n"
exit;