Get buddies bindings
[python-purple] / nullclient.py
1 import purple
2 import ecore
3 import getpass
4 import sys
5
6 class NullClient:
7     def __init__(self):
8         self.p = purple.Purple()
9         self.account = None
10
11     def execute(self):
12         self.p.purple_init()
13
14     def set_protocol(self, protocol):
15         for i in self.p.get_protocols():
16             if i[1] == protocol:
17                 print "-- NULLCLIENT --: Choosing %s as protocol" % protocol
18                 self.protocol = i[0]
19                 print "-- NULLCLIENT --: Protocol successfully chosen: %s" % i[0]
20                 return
21
22     def new_account(self, username, protocol, password):
23         self.account = purple.Account(username, protocol)
24         self.account.set_password(password)
25         self.account.set_enabled("carman-purple-python", True)
26
27 def getuser():
28     sys.stdout.write("GTalk account: ")
29     username = sys.stdin.readline()
30     return username[:-1]
31
32 def getpassword():
33     return getpass.getpass()
34
35 if __name__ == '__main__':
36
37     client = NullClient()
38     client.execute()
39     client.set_protocol("XMPP")
40     username = getuser()
41     password = getpassword()
42     client.new_account(username, client.protocol, password)
43
44     client.p.connect()
45     ecore.main_loop_begin()