19 March 2011

Easily Interact with the Skype API using Skype4Py

I have been working for a while on automating things that I do using Skype and Applescript. The primary task that I wish to automate is automatically dialing numbers from a call list one at a time and then dialing the next when I click a button on a simple graphical interface. So far I have a working Applescript version but when I came across a python library that was easier to use I thought I would give it a try.

To install Skype4Py just use setup tools and easy_install:
$ sudo easy_install Skype4Py
Here's a quick snippet that displays the users from your friend list that currently have a status that is not included in the badStatusCodes list. It's not much and doesn't perform any error handling but it shows just how easy it is to get started using this library.
import Skype4Py

s = Skype4Py.Skype()
s.Attach()
badStatusCodes = ['UNKNOWN', 'OFFLINE', 'DND', 'LOGGEDOUT']
availFriends = []
for f in s.Friends:
 if not f.OnlineStatus in badStatusCodes:
  availFriends.append(f)
  print "%s, %s" % (f.FullName, f.OnlineStatus)
It seems like quite a useful tool if you are into IP telephony or just want to screw around with creating Skype bots and the like.

Unfortunately Skype4Py doesn't work 100% on OS X because of an issue with threading (and I'm a mac user). For example, if I try to place a call using s.PlaceCall(number) it says that the thread can only be started one time
>>> s.PlaceCall() 
Traceback (most recent call last):
  File "", line 1, in 
  File "build/bdist.macosx-10.3-fat/egg/Skype4Py/skype.py", line 691, in PlaceCall
  File "build/bdist.macosx-10.3-fat/egg/Skype4Py/skype.py", line 877, in _GetActiveCalls
  File "build/bdist.macosx-10.3-fat/egg/Skype4Py/skype.py", line 339, in _Search
  File "build/bdist.macosx-10.3-fat/egg/Skype4Py/skype.py", line 276, in _DoCommand
  File "build/bdist.macosx-10.3-fat/egg/Skype4Py/skype.py", line 778, in SendCommand
  File "build/bdist.macosx-10.3-fat/egg/Skype4Py/api/darwin.py", line 374, in send_command
  File "build/bdist.macosx-10.3-fat/egg/Skype4Py/api/darwin.py", line 327, in attach
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 467, in start
    raise RuntimeError("threads can only be started once")
RuntimeError: threads can only be started once
The following resources are very helpful when working with Skype4Py:

No comments:

Post a Comment