Parsing Atom & Rss in Ruby/Rails

Parsing Atom & RSS in Ruby/Rails?

Feedzirra is one of the better options: http://www.pauldix.net/2009/02/feedzirra-a-ruby-feed-library-built-for-speed.html

Of course, I'm biased since I wrote it. :)

Extracting text values from atom feed with Ruby RSS

To get the content of the title your code should be as below :

require "rss"
feed = RSS::Parser.parse(open("http://casadelkrogh.dk/atom.xml").read)
feed.title.to_s
# => "<title>CasaDelKrogh</title>"
feed.title.content
# => "CasaDelKrogh"

Which is the best way to parsing RSS/Atom feeds with Rails

I can highly recommend feedzirra (it's a gem, really). I currently use FeedZirra in a production system that is continuously importing thousands of RSS and Atom feeds. It's very easy to use as well.

To your other points: no and no. A feed is a file on the web, which you need to download completely. You can however limit the number of articles you read or import into your database in your own code.

You need to parse the entire file, but it's possible to extract just the titles from each article.

Again, feedzirra makes this really easy for you to do.

http://github.com/pauldix/feedzirra/tree/master

High-performance RSS/Atom parsing with Ruby on Rails

I haven't tried it, but I read about Feedzirra recently (it claims to be built for performance) :-

Feedzirra is a feed library that is
designed to get and update many feeds
as quickly as possible. This includes
using libcurl-multi through the
taf2-curb gem for faster http gets,
and libxml through nokogiri and
sax-machine for faster parsing.

Rails library to process an RSS/ATOM feed?

I've seen good notes on the parsing part at http://www.robbyonrails.com/articles/2005/05/11/parsing-a-rss-feed (and links therefrom). How to best present things once you have parsed them is maybe a bit of a subjective issue...

Ruby Rss parser and event trigger

OK heres the deal.

  1. If you want a real fast feed parser go for Feedzirra. Does not work on windows. http://github.com/pauldix/feedzirra

  2. Autodiscovery?

    -Theres truffle-hog if you don't want to do GET redirects. http://github.com/pauldix/truffle-hog

    -Theres feedbag if you want to do GET redirects to find feeds from given urls. This is slower though. http://github.com/damog/feedbag

  3. Feedzirra is the best bet if you want to poll for new entries for your feed. But if you want a more non-polling solution to your problem then i would suggest going through the pubsubhubbub spec. Make sure while parsing your feeds they are pubsubhubbub enabled. Check for the link tag. If it points to pubsubhubbub.appspot.com or any other pubsub enabled hub then just subscribe to the feed by sending a subscription request to the hub. You can then define a endpoint in your app which will in turn receive updated entry pings for your feed subscription from the hub. Just read the raw POST data and store it in your database. Stats are that 95% of the blogger blogs are pubsub enabled. That is a lot of data in your hands already. :)

  4. If you are polling for changes then you should check the last-modified or etag from the header rather than parse the entire feed again. Saves you from wasting resources. Feedzirra takes care of this for you.

Atom feed and rss reader

I think you need to add the pubDate entry similar to the published:

And also the format of the dates.

for example:

atom_feed do |feed|
feed.title("Posts")
feed.pubDate(CGI.rfc1123_date(@posts.first.created_at))
feed.published(CGI.rfc1123_date(@posts.first.created_at))
feed.updated(CGI.rfc1123_date(@posts.first.created_at))

@posts.each do |post|
feed.entry(:url => post_path(post)) do |entry|
entry.title(post.title)
entry.pubDate(CGI.rfc1123_date(post.created_at))
entry.published(CGI.rfc1123_date(post.created_at))
entry.updated(CGI.rfc1123_date(post.created_at))
end
end
end

Rails: How can I parse an RSS file with Feedjira

It's weird that Feedjira::Feed.fetch_and_parse url wasn't working for you. It's working perfectly fine for me.

Here's how I did it. I'm using Railscasts RSS feed for example purpose:

url = "http://railscasts.com/subscriptions/rZNfSBu1hH7hOwV1mjqyLw/episodes.rss"
feed = Feedjira::Feed.fetch_and_parse url

feed.entries.each do |entry|
puts entry.title
end

How do I make an RSS/Atom feed in Rails 3?

Auto_discovery_link_tag is a good start. A quick Google search and I found blog posts on How to Create an RSS feed in Rails. Let me fill you in on what your associated controller/action is supposed to look like:

controllers/posts_controller.rb

def feed
@posts = Post.all(:select => "title, author, id, content, posted_at", :order => "posted_at DESC", :limit => 20)

respond_to do |format|
format.html
format.rss { render :layout => false } #index.rss.builder
end
end

The name of this file should match the controller. See, below:

views/posts/feed.rss.builder

xml.instruct! :xml, :version => "1.0" 
xml.rss :version => "2.0" do
xml.channel do
xml.title "Your Blog Title"
xml.description "A blog about software and chocolate"
xml.link posts_url

for post in @posts
xml.item do
xml.title post.title
xml.description post.content
xml.pubDate post.posted_at.to_s(:rfc822)
xml.link post_url(post)
xml.guid post_url(post)
end
end
end
end

This is where all the Railsy magic happens. Here, the RSS feed XML is generated and returned to HTTP.



Related Topics



Leave a reply



Submit