Destroying purple.core in nullclient.py
[python-purple] / nullclient.py
1 #
2 #  Copyright (c) 2008 INdT - Instituto Nokia de Tecnologia
3 #
4 #  This file is part of python-purple.
5 #
6 #  python-purple is free software: you can redistribute it and/or modify
7 #  it under the terms of the GNU General Public License as published by
8 #  the Free Software Foundation, either version 3 of the License, or
9 #  (at your option) any later version.
10 #
11 #  python-purple is distributed in the hope that it will be useful,
12 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 #  GNU General Public License for more details.
15 #
16 #  You should have received a copy of the GNU General Public License
17 #  along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 #
19
20 import getpass
21 import sys, dl
22 import time
23
24 sys.setdlopenflags(dl.RTLD_NOW | dl.RTLD_GLOBAL)
25
26 import purple
27
28 # The information below is needed by libpurple
29 __NAME__ = "nullclient"
30 __VERSION__ = "0.1"
31 __WEBSITE__ = "N/A"
32 __DEV_WEBSITE__ = "N/A"
33
34 if __name__ == '__main__':
35     # Sets initial parameters
36     core = purple.Purple(__NAME__, __VERSION__, __WEBSITE__, __DEV_WEBSITE__, \
37             debug_enabled=True, default_path="/tmp")
38
39     # Initializes libpurple
40     core.purple_init()
41
42     # Get username from user
43     sys.stdout.write("Enter GTalk account: ")
44     username = sys.stdin.readline()[:-1]
45
46     # Initialize protocol class
47     protocol = purple.Protocol('prpl-jabber')
48
49     # Creates new account inside libpurple
50     account = purple.Account(username, protocol, core)
51     account.new()
52
53     # Get password from user
54     account.set_password(getpass.getpass())
55
56     # Set account protocol options
57     info = {}
58     info['connect_server'] = 'talk.google.com'
59     info['port'] = '443'
60     info['old_ssl'] = True
61     account.set_protocol_options(info)
62
63     # Enable account (connects automatically)
64     account.set_enabled(True)
65
66     while True:
67         try:
68             core.iterate_main_loop()
69             time.sleep(0.01)
70         except KeyboardInterrupt:
71             core.destroy()
72             break