Vizible’s Blog

Pidgin – Change Status Message Every 5 Seconds

Posted in Programming by wearetherock on January 20, 2009
import dbus,gobject,time
from dbus.mainloop.glib import DBusGMainLoop

#DBusGMainLoop(set_as_default=True)

STATUS_OFFLINE = 1
STATUS_AVAILABLE = 2
STATUS_UNAVAILABLE = 3
STATUS_INVISIBLE = 4
STATUS_AWAY = 5
STATUS_EXTENDED_AWAY = 6
STATUS_MOBILE = 7
STATUS_TUNE = 8

def get_session_bus() :
  bus = dbus.SessionBus()
  return bus

def get_pidgin_object(object = None) :
  bus = get_session_bus()
  object = bus.get_object("im.pidgin.purple.PurpleService",
        "/im/pidgin/purple/PurpleObject")
  pidgin = dbus.Interface(object, "im.pidgin.purple.PurpleInterface")
  return pidgin
  

def set_new_status(pidgin, my_account  , message) :
    
  saved_status = pidgin.PurpleSavedstatusNew(message, STATUS_UNAVAILABLE)
  pidgin.PurpleSavedstatusSetMessage(saved_status, message)
  pidgin.PurpleSavedstatusActivateForAccount(saved_status, my_account)
  #pidgin.PurpleSavedstatusActivate(saved_status)

def main() :
  pidgin = get_pidgin_object()
  my_account = pidgin.PurpleAccountsFind("xxxxx@hotmail.com", "prpl-msn")

  believe = open("never_say_die.txt", "r")
  lines = believe.readlines()
  believe.close()

  while True :
    for line in lines :
      
      message = line.rstrip().strip()
      if message != '' :
        set_new_status(pidgin, my_account, message)
        print message
        
      time.sleep(5)
      pidgin.PurpleSavedstatusDelete(message)
    
if __name__ == "__main__" :
  main()
  
  
#pidgin.PurpleAccountSetAlias(my_account, "What's your name?")
#pidgin.PurpleAccountSetUserInfo(my_account, "Just test ")
  
#loop = gobject.MainLoop()
#loop.run()

# remove \n : http://stackoverflow.com/questions/275018/how-can-i-remove-chomp-a-newline-in-python
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: