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:I figured that might be a common enough piece of code, so I just added it to the code base.
You can now do this:
Sorting by date was handled automatically.
Need that as xml?
Wanted that in RSS 1 .0 and 2.0? No problem:
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.