Archive for the ‘atom’ Category

h1

Automatic blog posts from your Google Reader Shared items

September 9, 2007

You may notice every once in a while I have a post titled “items from” and some date, with the content being some (hopefully) interesting items I’ve read on the web that day. Creating that post looks like a simple matter of manually creating a new post, copying and pasting the title and a summary, then adding some formatting and publishing. While that isn’t too hard, even easier would be if you could just share interesting items in your Google Reader (using the “Share” link) during the day and have them magically appear later that night in your blog.

Below is a Ruby script I wrote that does just that. It consumes an Atom feed of your Google Reader Shared Items, formats them, and automatically posts them to your WordPress blog using their XML-RPC interface. You can run this manually, or schedule it to run at a specific time as a cron job. Note that this does not rely on inserting the post directly into the WordPress SQL tables as I’ve seen other WP plug-ins do - that requires you to have access to the WP database, which you don’t if (like me) your blog is hosted at wordpress.com.

This whole process takes less than 100 lines of Ruby, including lot’s of comments. What this shows is how easy it is to “glue” together different web services to accomplish a useful goal when all the players use well documented web standards. It also shows how simple, yet powerful, a dynamic scripting language designed for the web can be.

The script can be found here. Read the comments at the very top for examples of how to run it. Make sure you edit your personal settings in the “Stuff you should change” section.

Later, I’ll show you a similar script that automatically creates blog posts from your del.icio.us links.

h1

Google GData API

September 7, 2007

I’m doing a lot of reading right now about feed protocols like Atom. Google basically uses Atom to provide feeds for all their data sources, but they add a query component to it and call it GData. Man - this stuff is powerful, yet super easy to use. I guess that description pretty much sums up everything Google does.

An Atom feed is an XML standard that is very easy to parse/consume, either using straight XPath or with a language specific toolkit. In Ruby, I currently use FeedTools. Most browsers (I have tried Firefox and Safari) are able to display an Atom feed in a pleasant way, so you can enter the sample urls below right into them and see the results.

The parameters on these urls should be very self explanatory. Feel free to try different values, like changing the city name to your city.

Show videos on YouTube for homes for sale in Boca Raton:

http://gdata.youtube.com/feeds/videos?vq=home+for+sale+boca+raton&max-results=20

Show listings on Google Base for homes for sale in Boca Raton:

http://www.google.com/base/feeds/snippets?bq=home+for+sale+boca+raton&max-results=20

Obviously, these are pretty simple examples and just scratch the surface, but the point is that producing feeds using the Atom standard allows Google to expose their data in a standard, easily parsed format that are simple to consume.

I’ll have something soon on consuming your Google Reader shared items.

More YouTube GData developer docs here.

More Google Base GData developer docs here.