Prev / Next / あかぴのChangeLog by rchalow

kuttuki-rss.rbみたいなもの[chalow][修行]

2008-03-22

kuttuki-rss.rbみたいなもの [chalow][修行]

なんか kuttuki-rss.pl が動いてくれないので、
RSS Parserのsampleを切り貼り。オイにはこの程度で充分だ。
ありがとうございました>kouさま

#!/usr/bin/env ruby

$LOAD_PATH.unshift("/home/akapy/lib/ruby/rss/lib")
require 'rss'
require 'open-uri'

require "nkf"
class String
  # From tdiary.rb
  def shorten( len = 120 )
    lines = NKF::nkf( "-e -m0 -f#{len}", self.gsub( /\n/, ' ' ) ).split( /\n/ )
    lines[0].concat( '...' ) if lines[0] and lines[1]
    lines[0]
  end
end

def print_items(feed)
  puts "document.writeln('<h3>つっこみ一覧</h3><div class=\"stdbox\"><p>recent entries</p><ul class=\"stdbox\">')"
  feed.items.each do |item|
# puts "document.writeln('<li class=\"RSSitems\"> #{item.title.shorten(50)} : #{item.description.shorten(50)}</li>')"
    puts "document.writeln('<li class=\"stdbox\"> #{item.description.shorten(20)}</li>')"
  end
  puts "document.writeln('</ul></div>')"
end

#ARGV.each do |fname|
# feed = nil
# begin
# feed = RSS::Parser.parse(File.read(fname), false)
    rss = RSS::Parser.parse(open("http://pub.cozmixng.org/~akapy/ChangeLogMemo/kblog/bbs.rdf").read, false)
    rss.output_encoding = "euc-jp"

# rescue RSS::Error
# end

  if rss.nil?
    puts "#{fname}はRSS 0.9x/1.0/2.0, Atom 1.0のいずれでもありません。"
  else
    print_items(rss)
  end
#end


blog comments powered by Disqus