Sha256: b8c4a2a910e793ba0c516851cc4f12302f0c29714e0f5abc51d43b118a75787e

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

# -*- coding: utf-8 -*-
require 'rubygems'
require 'nokogiri'

require 'consadole_aggregator/nikkan_sports/entry'
require 'consadole_aggregator/nikkan_sports/parser'
require 'consadole_aggregator/nikkan_sports/builder'

module ConsadoleAggregator
  module NikkanSports
    def NikkanSports.list
      doc = Nokogiri::HTML.parse(Net::HTTP.get(Parser::List::BASE_URI), nil, 'UTF-8')
      Parser::List.parse doc
    end

    def NikkanSports.save
      NikkanSports.list.map(&:uri).each do |uri|
        doc = Nokogiri::HTML.parse(Net::HTTP.get(uri), nil, 'UTF-8').at('div#news')
        entry = Parser::Entry.parse doc, uri
        entry.save # DataMapper だと 一意制約違反でも例外にならない。ただ挿入できないだけ。
      end
    end

    def NikkanSports.rss
      entries = Entry.all(:order => [:post_date.desc], :limit => 20)

      Builder::Rss.build entries do |item, entry|
        item.link = entry.uri.to_s
        item.title = entry.title
        item.summary = "<div>#{entry.image ? entry.image.to_html + entry.text : entry.text}</div>"
        item.date = entry.post_date
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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