Skip to content

Instantly share code, notes, and snippets.

@quad
Created April 19, 2009 12:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quad/98043 to your computer and use it in GitHub Desktop.
Save quad/98043 to your computer and use it in GitHub Desktop.
A hilarious use of the Skype API to connect random people together.
#!/usr/bin/env python
import logging
import dbus
import dbus.service
import gobject
# Set DBUS as the default MainLoop.
from dbus.mainloop.glib import DBusGMainLoop
DBusGMainLoop(set_as_default = True)
class Receiver(dbus.service.Object):
def __init__(self, bus, object_path):
self.calls = {}
dbus.service.Object.__init__(self, bus, object_path)
@dbus.service.method(dbus_interface = 'com.Skype.API', in_signature = 's')
def Notify(self, message):
# Parse and normalize the incoming messages.
response = message.split()
response.reverse()
command = response.pop()
# Reconstruct the response for passing.
response.reverse()
message = ' '.join(response)
rpc = getattr(self, command.lower(), None)
if rpc:
rpc(message)
else:
self._no_handler(command, message)
def _no_handler(self, command, message):
logging.debug("%s [nh]: %s" % (command, message))
def _transfer(self, id):
logging.debug('TRANSFER %s' % id)
endpoints = [
# '+15093358477',
# '+12062299142',
# '+12066014490',
# '+13609084242',
'+4961034692902',
'+491707525081',
]
for num in endpoints:
assert 'TRUE' in self.skype.Invoke("GET CALL %s CAN_TRANSFER %s" % (id, num))
else:
nums = ', '.join(endpoints)
logging.debug(self.skype.Invoke("ALTER CALL %s TRANSFER %s" % (id, nums)))
def call(self, message):
response = message.split()
response.reverse()
id = response.pop()
logging.debug('CALL (%s): %s' % (id, message))
if 'STATUS' in response and 'RINGING' in response:
gobject.timeout_add(100, self._transfer, id)
def startup():
bus = dbus.SessionBus()
proxy = bus.get_object('com.Skype.API', '/com/Skype')
skype = dbus.Interface(proxy, 'com.Skype.API')
# Link us up to Skype and get the protocol flowing.
assert skype.Invoke('NAME forward-test') == 'OK'
command, version = skype.Invoke('PROTOCOL 7').split()
assert command == 'PROTOCOL'
assert int(version) >= 7
# Setup call forwarding. (this works, but not call transfer?!)
#skype.Invoke('SET PROFILE CALL_NOANSWER_TIMEOUT 2')
#skype.Invoke('SET PROFILE CALL_FORWARD_RULES 0,15,+12062299142 0,15,+12066014490')
#skype.Invoke('SET PROFILE CALL_APPLY_CF True')
# Export an object to receive incoming events.
r = Receiver(bus, '/com/Skype/Client')
r.skype = skype
def main():
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
gobject.timeout_add(0, startup)
# Startup the main loop.
loop = gobject.MainLoop()
loop.run()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment