Vizible’s Blog

Crazy IM !

Posted in Programming by wearetherock on January 4, 2009

source code …

import dbus, gobject

from dbus.mainloop.glib import DBusGMainLoop

DBusGMainLoop(set_as_default=True)
bus = dbus.SessionBus()

def gen_message():
  from os import popen
  x = popen('fortune')
  message = '\n';
  for line in x.readlines():
    message += line
    #y = popen('tweet  [test dbus] '+line)
  return message

def sent_fortune_message(account,sender):
  obj = bus.get_object("im.pidgin.purple.PurpleService",
	    "/im/pidgin/purple/PurpleObject")
  purple = dbus.Interface(obj, "im.pidgin.purple.PurpleInterface")
  conv = purple.PurpleConversationNew(1,account, sender)
  im = purple.PurpleConvIm(conv)
  message = gen_message()
  purple.PurpleConvImSend(im, message)

def received_response(account, sender, message, conversation, flags):
  print '----------------------------------------------'
  print "sent :", message
  sent_fortune_message(account,sender)
  
def sent_response(account, receiver, message):
  print '----------------------------------------------'
  print 'receive :' , message

bus.add_signal_receiver(received_response,
  dbus_interface='im.pidgin.purple.PurpleInterface',
  signal_name='ReceivedImMsg')
  
bus.add_signal_receiver(sent_response,
  dbus_interface='im.pidgin.purple.PurpleInterface',
  signal_name="SentImMsg")
  
loop = gobject.MainLoop()
loop.run()
Advertisements
Tagged with: , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: