I wanted to write this post ever since I’ve read Radu’s Fortune and Pidgin’s status on Ubuntu post. Radu’s approach is quite lame and hard to use, because it relies on the user exporting a SQL dump file every time he posts something on the blog.
And really, do you need *all* the posts in the database? Do you really want to advertise blog entries from 2 years ago? Come on!
My idea is much better…obviously
…and it goes like this: parse the blog’s RSS and take “inspiration” from there for the statuses. The weapon of choice for this task is python with its feedparser library.
First, some prerequisites:
sudo apt-get install python-feedparser
…and then, the python script:
#!/usr/bin/python import feedparser import random import os # feed url FEED = 'http://feeds2.feedburner.com/motanelu' feed = feedparser.parse( FEED ) index = random.randrange(0, len( feed['items'] ) - 1 ) status = 'purple-remote "setstatus?status=available&message=%s %s"' % ( feed['items'][index].title, feed['items'][index].link ) os.system( status ) # EOF
I consider this approach better than Radu’s, because it doesn’t require exporting the database or messing around with fortune. Read this post to see how to update Pidgin’s status using cron. And enjoy
My ideea was a pure raw thought. Therefore it can’t be lame because it hasn’t had the time to develop into something more rafined. But I do have some questions regarding your technique:
what do you do in case you want to exclude some posts from your feed?
if you set the
cronjob to run every 5 minutes, wouldn’t it be lame to load the exact same feed from 5 to 5 minutes?I must admit that using Python you have a lot more space for customizing the idea, but the intelligent approach would be to build a file to hold your entries for some time rather than querying the feed whenever you want your status to be changed.
The feed contains the latest info from your blog and since I choose a random item from the feed each time, if you run cron every 5 minutes, you will have a different item every time in your status.
And dude…that’s why we have RSS feeds, to query them whenever necessary. Feed readers query feeds all the time to see if you they contain new information. And it’s easier and more logical this way, rather than exporting a new SQL dump file after each post. What if you post 3 or 4 times a day? Will you go to all that trouble every time? I’m sure that you can make an automation script, but still…
Does it hurt to say that I was right this time? After all, it’s written in python, a language you evangelised to me for so long and in the beginning I was refering to it as gaython
Thanks for the script. Instead of using cron, I added it to the launcher so that I have a different status every time I go online.
scribu> is it better than Radu’s? Is it…come on
I need this
It’s easier, I’ll give you that.
I used your script to change my Pidgin’s status. It’s a bit slow (because of the time spent on querying the feed) but it’s more easy to use than mine. One alteration though:
This one is needed if you have ‘ (apostrophes) in your post’s title.
Check this out: Python and Pidgin’s status on Ubuntu (Linux).