# -*- coding: utf-8 -*- require 'kconv' require 'rss' require 'rubygems' require 'hpricot' # 2009/12/26 現在 GAE では nokogiri が使えないので hpricot module ConsadoleAggregator module NikkanSports FEED_URI = URI.parse('http://www.nikkansports.com/rss/soccer/jleague/consadole.rdf') def NikkanSports.uris rss = RSS::Parser.parse(FEED_URI, false) rss.items.map(&:link) end class Entry IMAGE_BASE_URI = URI.parse('http://cache2.nipc.jp/soccer/news/') def initialize doc @doc = Hpricot(doc) end def uri URI.parse(@doc.at('a')['href']) end def title @doc.at('h1').inner_text end def text @doc.search('div#news p')[0...-1].to_html.gsub(/【.+】<\/p>$/,'

') end def auther @doc.search('div#news p')[0...-1].to_html.match(/【(.+)】<\/p>$/)[1] end def post_date Time.strptime(@doc.search('p.timeStamp').inner_text.match(/\d+年\d+月\d+日\d+時\d+分/).to_s, '%Y年%m月%d日%H時%M分') end def image if tmp = @doc.at('dl.photo img') Image.new(IMAGE_BASE_URI + tmp['src'].sub(/\.jpg$/, '-big.jpg'), tmp['alt']) end end end end end