Funked Out Java+Ruby Aggregator #
Tim Bray. What a newb. But for being a Ruby nuby, he’s already posting hacks like he’s got recalescent digits. This JRuby stuff he’s got up right now makes me whinny!
 # Rename Java's Data class as JDate in Ruby
 include_class('java.util.Date') {|p,n| "J" + n }
 # Use Java's RSS/XML libs to fill a Ruby array
 ARGV.each do |arg| 
   feed = SyndFeedInput.new.build(XmlReader.new(URL.new(arg)))
   feed.entries.each do |entry|
     entry.setTitle "#{feed.getTitle}: #{entry.getTitle}" 
     aEntries << entry
   end
 end
 # Sort the entries in Ruby
 aEntries = aEntries.select { |e| e.getPublishedDate.between?(earlier, now) }
 aEntries.sort! { |a, b| b.getPublishedDate <=> a.getPublishedDate }
 aFeed.setEntries aEntries
	Get the picture? The script of note is here. (The original agog struck on Tim’s blog.)


 

sporkmonger
Very funky indeed, but might perhaps be easier and less frankenstein-like with FeedTools instead of Rome? I think (not certain, having never used Rome) that my library does all of the same things Rome does. Thus far, FeedTools is sort of the unholy bastard child of the Universal Feed Parser and Rome… though I have many plans for further scariness.
This is kinda what I would imagine his code would look like if done with FeedTools:# Creates a merged "planet" feed from a set of urls. def FeedTools.build_merged_feed(url_array) return nil if url_array.nil? merged_feed = Feed.new url_array.each do |feed_url| feed = Feed.open(feed_url) merged_feed.entries.concat( feed.entries.collect do |entry| entry.title = "#{feed.title}: #{entry.title}" entry end ) end return merged_feed endI figured that might be a common enough piece of code, so I just added it to the code base.
You can now do this:
require 'rubygems' require 'feed_tools' ruby_planet = FeedTools.build_merged_feed(['http://www.rubyweeklynews.org/index.xml', 'http://redhanded.hobix.com/index.xml', 'http://weblog.rubyonrails.com/xml/rss/feed.xml']) pp ruby_planet.entries.collect { |entry| entry.title } ["RedHanded: Funked Out Java+Ruby Aggregator", "Riding Rails: How to integrate FCKEditor and Rails", "Riding Rails: Rails is reaching the tipping point", "RedHanded: The Lately Hoodwink'd", "Ruby Weekly News: 22nd - 28th August 2005", "RedHanded: YAML is Parseltongue", "RedHanded: MUD in 15 Lines of Ruby", "RedHanded: Hobix and Rails Wed Unceremoniously Off Behind the Podomatic", "RedHanded: A MouseHole Example: Showing Alt Text", "Riding Rails: Alonovo: Socially-responsible shopping on Rails", "Riding Rails: Cartographer: Effortless Google Maps in Rails", "RedHanded: The Javascript-Ruby Connection Slims", "RedHanded: Announcing the MouseHole Proxy", "RedHanded: Hoodlums IV: No Sleep Till Borken", "Riding Rails: Why Ryan Tomayko switched to Ruby on Rails", "Riding Rails: Get taggable like all the cool kids", "Riding Rails: How Ruby on Rails can ease the life of managers", "Riding Rails: Sam Ruby takes Rails to Sri Lanka FOSSSL", "RedHanded: Nearing Greasemonkey for Browser-of-Choice with the Hoodlum Proxy!", "RedHanded: No, XPath on Messy HTML is Just as Easy in Ruby", "Riding Rails: Using Ajax to route dangerous methods through POST", "Riding Rails: Don't look at Rails if you have to do .NET", "Ruby Weekly News: 15th - 21st August 2005", "RedHanded: The Coast is Clear to Vocally Praise RubyGems", "RedHanded: Hoodwink'd, Day Three: Clearness of Vision", "RedHanded: Hoodwink'd, Day Two: Five Infiltrations", "RedHanded: DRb Inside Stored Procs", "RedHanded: Hoodwink'd, Day One: Forcing the Host to Attend the Party", "RedHanded: The Least Surprised #7: Definitely Go Where Everybody Already Knows You're Great", "RedHanded: If You Don't Get Symbols", "RedHanded: Docs Piling Up With Regard to Ajax and Ruby", "RedHanded: Oocli Fantasies", "Ruby Weekly News: 8th - 14th August 2005", "Ruby Weekly News: 27th June - 10th July 2005", "Ruby Weekly News: 13th - 26th June 2005", "Ruby Weekly News: 6th - 12th June 2005", "Ruby Weekly News: 30th May - 5th June 2005", "Ruby Weekly News: 23rd - 29th May 2005", "Ruby Weekly News: 16th - 22nd May 2005", "Ruby Weekly News: 2nd - 15th May 2005"] => nilSorting by date was handled automatically.
Need that as xml?
ruby_planet.title = "Super-Cool Ruby Planet" ruby_planet.link = "http://no.where/yet?" ruby_planet.description = "Get yer Ruby right here!" ruby_planet.build_xml("atom", 0.3) => (XML Builder object, suitable for use with Rails)Wanted that in RSS 1 .0 and 2.0? No problem:
ruby_planet.build_xml("rss", 1.0) ruby_planet.build_xml("rss", 2.0)So yeah, grab 0.2.6 while it’s hot, I guess…
sporkmonger
Also, perhaps worth noting, I don’t think Tim Bray was the author of that aggregator. Tom Enebo perhaps?
Tim Bray
Definitely Tom’s code, not mine. The real point is, Rome is a Java thingie and the difference between how one uses said thingie from Ruby vs. Java is, um, instructive.
My beard is white… being called a n00b is (blush) a good feeling these days.
topfunky
Definition of recalescent
He has glowing white digits that increase in heat during the cooling process?
Wha?
sporkmonger
Tim, it certainly was interesting to look it, though I have to admit, interfacing Java with Ruby creeps me out just a little.
Manfred
Ruby is just very politically correct: it has no boundaries and understands multiple languages.
Danno
Dagnabit Sporkmonger! Where was your library when I was pondering a need for a Universal Feed Parser in Ruby on like, June 26th?! (and then subsequently decided to start a half baked one on my own)
But sewiously, Awesome… one question: How does it handle namespaces in the various formats?
sporkmonger
Danno: According to RubyForge, REL 0 .1.0 of FeedTools was hatched on June 27th. On the 26th it was merely a twinkle in my eye!
Regarding namespaces, it’s currently a namespace-unaware parser. Which is to say, it isn’t perfect yet, however, I’m working on plugging in support for namespaces for the 0.3.0 release. It is, however, still aways away. Lots of work to be done. In the meantime, it does its best, and manages to get things right most of the time.
Manfred: Oh, Ruby’s all politically correct, plays well with others and all… but… what about aesthetics? Think of the children!
Tim Bray
And, sporkboy, until it does Atom 1.0, it’s a toy.
why
sporkmonger, the guys in winkyland are loving you. radu gave you a single ruby: [>
radu
more rubies for sporkboy! (careful, don’t eat the strawberry!)
[> [> [> {> [>
sporkmonger
Tim: Not sure if I’m reading you wrong, but that seemed a little unfriendly. Version 0.2.6 does mostly handle Atom 1.0, at least for parsing. It didn’t do Atom 1.0 output, but that’s mainly because I’ve personally only had a need for the parsing methods. But just for you, cuz I actually kinda like ya, I just put out a quickie release of 0.2.7 with much more complete Atom 1.0 support in. The output from the merged feed code from before now validates perfectly as Atom 1.0.
As for the “toy” accusation, actually, I agree with you. It is a toy, for the moment. That’s why it’s got a big “0” prefixing the version number. But as toys go, I’d like to think it’s a dang nifty one.
Oh, by the way, I altered the merge feeds method to be multithreaded, so it retrieves the feeds concurrently.
radu: Awww, thanks.
Comments are closed for this entry.