The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Gathering local copies of feeds

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Adam Green

Posts: 102
Nickname: darwinian
Registered: Dec, 2005

Adam Green is the author of Ruby.Darwinianweb.com
Gathering local copies of feeds Posted: Dec 30, 2005 12:17 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Adam Green.
Original Post: Gathering local copies of feeds
Feed Title: ruby.darwinianweb.com
Feed URL: http://www.nemesis-one.com/rss.xml
Feed Description: Adam Green's Ruby development site
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Adam Green
Latest Posts From ruby.darwinianweb.com

Advertisement
I could have the aggregator retrieve the lastest version of the feeds and combine them in one step, but as I wrote earlier, storing them locally first has some advantages. You may notice that I avoiding using the word RSS in my code. I plan on supporting Atom as well as RSS, so I'm trying to stick with the more generic term of feeds.

gather_feeds.rb

 #! /usr/bin/ruby
# Download files to be aggregated into a local cache



require "get_param"
cachedir = get_param("rubyriver.yml","cachedir")



# The feedlist for RubyRiver is rubyriver.opml
feedlist = get_param("rubyriver.yml","feedlist")



# Record failures in an error log for later analysis
logdir = get_param("rubyriver.yml","logdir")
logname = Time.now.strftime(logdir + "/%Y%m%d-%H%M.txt")



# Read rubyriver.opml into memory for XML parsing
require "open-uri"
require "rexml/document"
include REXML
opmlfile = File.open(feedlist)
opmldoc = Document.new(opmlfile.read)



# Local copies of the feeds will be given sequential file names
id = 1



# Gather the feeds
opmldoc.elements.each("opml/body/outline/outline") do |item|
begin
# Read remote copy
remotefile = open(item.attributes["xmlUrl"] )
localfile = File.open(cachedir + "/" + id.to_s + ".xml", "w")



# Save local copy
localfile.puts( remotefile.read )
remotefile.close
localfile.close



rescue Exception
# Log errors
logfile = File.open(logname,"a+")
logfile.puts(item.attributes["title"])
logfile.puts(feedurl)
logfile.close
end



id += 1
end
opmlfile.close

Read: Gathering local copies of feeds

Topic: Ruport 0.5.0 Specification Previous Topic   Next Topic Topic: Some sad news

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use