# -*- coding: utf-8 -*- require 'net/http' require 'kconv' 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.toutf8 item.title = entry.title.toutf8 item.summary = "