Python and Pidgin’s status on Ubuntu (Linux)
If you remember Fortune and Pidgin’s status on Ubuntu (Linux), Tudor has found a better solution to accomplish this using Python. I did argue with him a bit regarding the number of requests made (you can see that in the comments on his blog post) but finally I would agree that his solution was better than mine, only that I felt the need to improve it a bit. This still needs to set DBUS session parameters at log in time, and thanks to Earl Ruby this can be done easily too.
The script is pretty simple and I made it write a log to stdout, which with the help of cron can be piped to any file you want. Knock yourself out:
#!/usr/bin/python
# pidgin_status_change.py
"""
Handy script for changing Pidgin's status with a post from a feed passed as argument.
Usage:
python pidgin_status_change.py your_feed_link
Authors:
Tudor Barbu, http://motane.lu
Radu Cotescu, http://radu.cotescu.com
"""
import commands
import feedparser
import random
import os
import sys
import time
# feed url
FEED = []
def setFeed():
if sys.argv is not None and len( sys.argv ) < 3:
global FEED
FEED = sys.argv[1]
def changeStatus():
if len( FEED ) is not None:
if commands.getoutput('pidof pidgin') is not None:
feed = feedparser.parse( FEED )
index = random.randint( 0, len( feed['items'] ) - 1 )
print time.strftime("%d-%m-%Y, %H:%M:%S", time.localtime())
print """\tStatus:\n\t%s\n\t%s""" % ( feed['items'][index].title.encode("utf-8"), feed['items'][index].link.encode("utf-8") )
status = 'purple-remote "setstatus?status=available&message=%s %s"' % ( feed['items'][index].title, feed['items'][index].link )
os.system(status.encode("utf-8"))
setFeed()
changeStatus()
# EOF
Download it from here.
Setting your DBUS session parameters requires exporting some variables to your environment. Take the script below and add it via System – Preferences – Startup Applications to the list of programs that start at log in. This way you’ll always be sure the needed variables are available.
#!/bin/bash #Export the dbus session address on startup so it can be used by cron touch $HOME/.Xdbus chmod 600 $HOME/.Xdbus env | grep DBUS_SESSION_BUS_ADDRESS > $HOME/.Xdbus echo 'export DBUS_SESSION_BUS_ADDRESS' >> $HOME/.Xdbus # Export XAUTHORITY value on startup so it can be used by cron env | grep XAUTHORITY >> $HOME/.Xdbus echo 'export XAUTHORITY' >> $HOME/.Xdbus
Download this one from here.
Then you only need to set cron to do the job:
SHELL=/bin/bash DISPLAY=:0.0 */5 * * * * source ~/.Xdbus; /home/radu/scripts/pidgin_python/pidgin_status_change.py http://feeds2.feedburner.com/raducotescu >> /home/radu/crontab.log
Happy blogging!
You might also like:
1 Comment
Leave a comment
Recent Posts
Projects that I support
Recent Comments
nope said:
yeah that was my first thought too, but: mount: warning: seems to be mounted read-write. too bad, would have been just perfect. more»Klaus Deiss said:
Dear Radu, I tried it on Ubuntu 10.0.4.2 and 10.0.4.3 with different kernel versions (amd64 server 2.6.32 kernel). No... more»scompo said:
Nope.. Now it’s not working again.. This printer it’s a real pain in the butt.. The other hp printer I had... more»Dmitrij said:
Thank you Peter and Patrice. Could you please post the updated script? more»hd_flash_pains said:
didn’t work for me more»








[...] the same principle as the script I wrote for updating Pidgin’s status with a random post from your blog’s feed, this new script uses as well a feed (the one provided by Twitter to every user), only that this [...]