#!/usr/bin/env ruby require 'net/http' Net::HTTP.version_1_2 require 'rss/1.0' require 'rss/2.0' # require 'rss/dublincore' ################################# TITLE = "faw's personal RSS" MAXITEMS = 5 RSSFILENAME = "rss.txt" VERSION = "0.0.1" ################################# def parse_rss(rss_source) rss = nil begin rss = RSS::Parser.parse(rss_source) rescue RSS::InvalidRSSError rss = RSS::Parser.parse(rss_source, false) end if rss.nil? puts "#{fname} does not include RSS 1.0 or 0.9x/2.0" else begin rss.output_encoding = "euc-jp" rescue RSS::UnknownConversionMethodError error($!) if verbose end end return rss end def get_rss(url) if url !~ /^http:\/\/([^\/]+)(\/.*)$/ STDERR.print "only http with full hostname(last '/' required)is supported\n" exit end hostport = $1 path = $2 if (hostport =~ /^(.*):([0-9]+)$/) host = $1 port = $2 else host = hostport port = 80 end if host =~ /^\[(.*)\]$/ host = $1 end # STDERR.print "url=<#{url}>\n" # STDERR.print "host=<#{host}>\n" # STDERR.print "path=<#{path}>\n" return Net::HTTP.get(host, path) end def print_items(rss) $count = 1 begin rss.output_encoding = "EUC-JP" rescue RSS::UnknownConversionMethodError end if rss.items == nil return end rss.items.each do |item| # items << item if item.dc_date if ($count > MAXITEMS) then break end $count += 1 if (item == nil) continue end print_rss_item(item) end # print_sort_items(items) end def print_rss_item(item) print "
\n#{item.description}\n
\n" end # def print_sort_items(items) # items.sort do |x, y| # y.dc_date <=> x.dc_date # end.each do |item| # puts "#{item.dc_date.localtime.iso8601} : #{item.title} : #{item.description}" # end # end def print_html_header() print "\n" print "\n" print "\n" print "\n" print "