Sha256: cfc54ba0b6be548e7b0df71cd8d130683f7f54a11896fb8b9349ef20fa9dd450

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

# -*- 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.toutf8)
      end

      def uri
        URI.parse(@doc.at('a')['href'])
      end

      def title
        @doc.at('h1').inner_text.toutf8
      end

      def text
        @doc.search('div#news p')[0...-1].to_html.toutf8.gsub(/【.+】<\/p>$/,'</p>')
      end

      def auther
        @doc.search('div#news p')[0...-1].to_html.toutf8.match(/【(.+)】<\/p>$/)[1]
      end

      def post_date
        Time.strptime(@doc.search('p.timeStamp').inner_text.toutf8.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'].toutf8)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
consadole_aggregator-0.0.1 lib/consadole_aggregator/nikkan_sports.rb