#!/usr/bin/env ruby # This code comes from http://ruby-it.org/pages/RitPlanet+0_1 # Check the page for copyright notice and explanations http://www.repubblica.it/rss/scienza_e_tecnologia/rss2.0.xml http://programmazione.it/rss.xml http://www.hwupgrade.it/rss_news.xml http://www.hwupgrade.it/rss_articoli.xml http://www.beppegrillo.it/index.xml http://ruby-it.org/feed.rss RubyIT Planet

RitPlanet

<% for item in @items %>

<%= item.title %>

<%= item.description %>

<% end %>

#!/usr/bin/env ruby require 'rss/2.0' require 'open-uri' require 'erb' module RIT class PlanetItem attr_reader :title, :link, :description, :date, :channel_title, :channel_link def initialize(params) @title = params[:title] @link = params[:link] @description = params[:description] @date = params[:date] @channel_title = params[:channel_title] @channel_link = params[:channel_link] end end class Planet attr_reader :items def initialize(file_name) @urls = [] @items = [] open(file_name) do |file| file.readlines.grep /^[^#]/ do |line| @urls << line.strip end end start end def start for url in @urls begin open(url) do |http| response = http.read result = RSS::Parser.parse(response, false) begin for item in result.items @items << PlanetItem.new( :title => item.title, :link => item.link, :description => item.description, :date => item.date, :channel_title => result.channel.title, :channel_link => result.channel.link ) end rescue puts "Problemi nella lettura del feed #{url}" end end rescue puts "Error: impossibile contattare l'url #{url}" end end end def render(tpl, file_name) tpl = ERB.new(open(tpl).read) result = tpl.result(binding) open(file_name, 'w') do |file| file.write(result) end end end end rp = RIT::Planet.new('urls.txt') rp.render('tpl.rhtml', 'blogs.html')