#!/usr/bin/ruby $LOAD_PATH.push '/usr/local/etc' class String def urlencode unpack('H*').first.upcase.gsub(/(..)/, "%\\1") end end class Time def rfc1123 utc.strftime('%a, %d %b %Y %H:%M:%S GMT') end def jst (utc + 32400).strftime('%Y-%m-%d %H:%M:%S') end def mysql utc.strftime('%Y-%m-%d %H:%M:%S') end def to_atom fmt = ('%%Y-%%m-%%dT%%H:%%M:%%S.%06uZ' % usec) utc.strftime(fmt) end MONTAB = { :jan => 1, :feb => 2, :mar => 3, :apr => 4, :may => 5, :jun => 6, :jul => 7, :aug => 8, :sep => 9, :oct => 10, :nov => 11, :dec => 12 } def Time.parse str begin case str when Mysql::Time then # considered UTC ymdhms = [:year, :month, :day, :hour, :minute, :second].map{|sym| str.send(sym) } STDERR.puts ymdhms.inspect if $DEBUG if ymdhms.first.zero? then nil else Time.gm(*ymdhms) end when /(\d+)\s+(\w+)\s+(\d+)\s+(\d+):(\d+):(\d+)\s+GMT/ then d, m, y, h, n, s = $1, $2, $3, $4, $5, $6 d, y, h, n, s = [d, y, h, n, s].map{|s| s.to_i} m = MONTAB[m.downcase.to_sym].to_i Time.gm(y, m, d, h, n, s) when /(\d+)-(\d+)-(\d+)[T ](\d+):(\d+):(\d+(?:\.\d+)?)Z/ then y, m, d, h, n = [$1, $2, $3, $4, $5].map{|s| s.to_i} s = $6.to_f Time.gm(y, m, d, h, n, s) when /(\d+)-(\d+)-(\d+)[T ](\d+):(\d+):(\d+(?:\.\d+)?)([-+]\d\d):?(\d\d)/ then y, m, d, h, n, zh, zn = [$1, $2, $3, $4, $5, $7, $8].map{|s| s.to_i} STDERR.puts [y, m, d, h, n, s, zh, zn].inspect if $DEBUG s = $6.to_f Time.gm(y, m, d, h, n, s) - (zh * 60 + zn) * 60 else raise "unknown datetime format '#{str}'" end rescue => e STDERR.puts "\t" + e.backtrace.join("\n\t") Time.now end end end module PSHBSpool class HtmlFeed def initialize url, css, title = 'title' require 'rexml/document' require 'digest/md5' @url, @css, @title = url, css, title @n = 0 @updated = Time.at(0) # to be completed by compile() @doc = @root = @ul = nil @cols = %w< updated title > end def add_col *name name.each{|n| @cols.push(n.to_s) } end def ins_link @cols.unshift('link') end COLN = { 'updated' => '発表時刻', #MAX(utime) 'title' => '表題', 'author' => '発表官署名', #pbof 'summary' => '見出し', 'Xstatus' => '運用種別', 'Xedof' => '編集官署名', 'Xitype' => '情報形態', 'Xevid' => '識別情報', 'Xexpire' => '有効期限', 'Xrtime' => '公式発表時刻', 'abr' => 'データ種類コード', } require 'pshbspool-cfg' PRMS = PSHBSpool::PRMS def compile return if @doc ths = @cols.map{|name| "