Tudor has found a better solution to advertise one’s blog posts with the help of Pidgin and a little bit of 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_linkAuthors: Tudor Barbu, http://motane.lu Radu Cotescu, http://radu.cotescu.com"""importcommandsimportfeedparserimportrandomimportosimportsysimporttime# feed urlFEED=defsetFeed():ifsys.argvisnotNoneandlen(sys.argv)<3:globalFEEDFEED=sys.argvdefchangeStatus():iflen(FEED)isnotNone:ifcommands.getoutput('pidof pidgin')isnotNone:feed=feedparser.parse(FEED)index=random.randint(0,len(feed['items'])-1)printtime.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
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 crontouch $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 cronenv | grep XAUTHORITY >> $HOME/.Xdbus
echo'export XAUTHORITY' >> $HOME/.Xdbus