Change Your Skype Mood Text In Linux With Python
I thought it would be neat to change my Skype mood text based on what I was watching on my WDTV. I have a WDTV Live Plus modded with WDLXTV (version 0.5.1.1 based on 1.05.04) that displays what I am watching on a web dashboard. To accomplish this, it is as simple as scraping the data from the dashboard and passing it to Skype using Skype’s API. On Linux, Skype uses D-Bus to interact with its API. The scripts I used are below.
#!/usr/bin/python # script to change Skype mood status, usage: skype_mood.py new_mood import dbus import sys def mood(text=""): bus = dbus.SessionBus() try: proxy = bus.get_object('com.Skype.API', '/com/Skype') proxy.Invoke('NAME skype_mood.py') proxy.Invoke('PROTOCOL 2') if text=="": command = 'GET PROFILE MOOD_TEXT' else: command = 'SET PROFILE MOOD_TEXT %s' % text return proxy.Invoke(command) except: print "Could not contact Skype client" if __name__ == "__main__": if len(sys.argv) >= 2: mood(sys.argv) else: print mood()
import urllib2 import re from skype_mood import mood wdlxtvurl = "http://WDLXTVURL/" defaultmood = "Nothing Playing" try: content = urllib2.urlopen(wdlxtvurl).read() except: print "Could not reach server" mood(defaultmood) exit() m = re.search('id="deviceStatus".*?>(.*?)<', content) status = m.group(1).strip() if status in ("PLAYING", "PAUSED_PLAYBACK"): m = re.search('id="currentMedia".*?>(.*?)<', content) playing = m.group(1).strip() print mood(playing) else: mood(defaultmood)
The first script, skype_mood.py, is a generic script. The second script imports the first one, grabs the relevant information from WDLXTV’s dashboard and if media is playing or paused, it will display the name or file name of the media as your mood status text in Skype. I had difficulty passing basic authentication credentials (urllib’s password manager or adding an authentication header) to my WDLXTV so I decided to remove the authentication altogether. If you want to run this with cron, you will need to configure some extra things detailed here.
Categorised as: Programming