Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 144 lines (114 sloc) 4.437 kb
971ccb2 @asabil - Started client implementation
asabil authored
1 #!/usr/bin/env python
2
3 import pymsn
efd668d @asabil - Updated the test.py to match the new API
asabil authored
4 import pymsn.event
971ccb2 @asabil - Started client implementation
asabil authored
5
5168659 - Added custom emoticons support.
Johann Prieur authored
6
971ccb2 @asabil - Started client implementation
asabil authored
7 import logging
8 import gobject
9
10 logging.basicConfig(level=logging.DEBUG)
11
12 finished = False
72bfb1d @asabil - Merged jprieur's branch
asabil authored
13
971ccb2 @asabil - Started client implementation
asabil authored
14 def get_proxies():
15 import urllib
16 proxies = urllib.getproxies()
17 result = {}
02416ce @asabil - Updated pymsn to the new gio
asabil authored
18 if 'https' not in proxies and \
19 'http' in proxies:
20 url = proxies['http'].replace("http://", "https://")
21 result['https'] = pymsn.Proxy(url)
971ccb2 @asabil - Started client implementation
asabil authored
22 for type, url in proxies.items():
23 if type == 'no': continue
92b93ce @asabil - Cleaned up the SwitchboardManager a bit
asabil authored
24 if type == 'https' and url.startswith('http://'):
25 url = url.replace('http://', 'https://', 1)
971ccb2 @asabil - Started client implementation
asabil authored
26 result[type] = pymsn.Proxy(url)
27 return result
28
9e686e1 @asabil - Conversations are usable now
asabil authored
29
30 class ClientEvents(pymsn.event.ClientEventInterface):
31 def on_client_state_changed(self, state):
32 if state == pymsn.event.ClientState.CLOSED:
33 self._client.quit()
34 elif state == pymsn.event.ClientState.OPEN:
35 self._client.profile.display_name = "Kimbix"
1c0d9c1 @asabil - Enhancements/bugfixes to the SwitchboardManager
asabil authored
36 self._client.profile.presence = pymsn.Presence.ONLINE
0924e58 @asabil - Merged jprieur's branch
asabil authored
37 self._client.profile.current_media = ("I listen to", "Nothing")
38 #self._client.profile.personal_message = "Testing pymsn, and freeing the pandas!"
3c64797 @asabil - Merged Johann's Typing notifications, and text formatting code
asabil authored
39 gobject.timeout_add(5000, self._client.start_conversation)
9e686e1 @asabil - Conversations are usable now
asabil authored
40
41 def on_client_error(self, error_type, error):
42 print "ERROR :", error_type, " ->", error
43
44 class AnnoyingConversation(pymsn.event.ConversationEventInterface):
45 def on_conversation_user_joined(self, contact):
46 gobject.timeout_add(5000, self.annoy_user)
47
48 def annoy_user(self):
5168659 - Added custom emoticons support.
Johann Prieur authored
49 msg = "Let's free the pandas ! (testing pymsn)"
3c64797 @asabil - Merged Johann's Typing notifications, and text formatting code
asabil authored
50 formatting = pymsn.TextFormat("Comic Sans MS",
5168659 - Added custom emoticons support.
Johann Prieur authored
51 pymsn.TextFormat.UNDERLINE | pymsn.TextFormat.BOLD,
52 'FF0000')
53 self._client.send_text_message(pymsn.ConversationMessage(msg, formatting))
2e0d45b - Fixed typo.
Johann Prieur authored
54 # self._client.send_nudge()
55 # self._client.send_typing_notification()
9e686e1 @asabil - Conversations are usable now
asabil authored
56 return True
57
2e0d45b - Fixed typo.
Johann Prieur authored
58 def on_conversation_user_typing(self, contact):
59 pass
60
5168659 - Added custom emoticons support.
Johann Prieur authored
61 def on_conversation_message_received(self, sender, message):
62 pass
3c64797 @asabil - Merged Johann's Typing notifications, and text formatting code
asabil authored
63
9e686e1 @asabil - Conversations are usable now
asabil authored
64 def on_conversation_error(self, error_type, error):
65 print "ERROR :", error_type, " ->", error
66
67 class Client(pymsn.Client):
41a2c90 @asabil - Fixed GNet protocol/HTTP.py http proxy authentication support
asabil authored
68 def __init__(self, account, quit, http_mode=False):
ebc2c89 @asabil - Added initial switchboard protocol implementation
asabil authored
69 server = ('messenger.hotmail.com', 1863)
971ccb2 @asabil - Started client implementation
asabil authored
70 self.quit = quit
ebc2c89 @asabil - Added initial switchboard protocol implementation
asabil authored
71 self.account = account
41a2c90 @asabil - Fixed GNet protocol/HTTP.py http proxy authentication support
asabil authored
72 if http_mode:
73 from pymsn.transport import HTTPPollConnection
ebc2c89 @asabil - Added initial switchboard protocol implementation
asabil authored
74 pymsn.Client.__init__(self, server, get_proxies(), HTTPPollConnection)
41a2c90 @asabil - Fixed GNet protocol/HTTP.py http proxy authentication support
asabil authored
75 else:
ebc2c89 @asabil - Added initial switchboard protocol implementation
asabil authored
76 pymsn.Client.__init__(self, server, proxies = get_proxies())
9e686e1 @asabil - Conversations are usable now
asabil authored
77 ClientEvents(self)
4e39701 @asabil - Added some callbacks to Client
asabil authored
78 gobject.idle_add(self._connect)
971ccb2 @asabil - Started client implementation
asabil authored
79
4e39701 @asabil - Added some callbacks to Client
asabil authored
80 def _connect(self):
ebc2c89 @asabil - Added initial switchboard protocol implementation
asabil authored
81 self.login(*self.account)
971ccb2 @asabil - Started client implementation
asabil authored
82 return False
83
9e686e1 @asabil - Conversations are usable now
asabil authored
84 def start_conversation(self):
85 contacts = self.address_book.contacts.\
6b64383 @asabil - Improved the msnp2p support
asabil authored
86 search_by_presence(pymsn.Presence.ONLINE)
7544026 @asabil - Merged jprieur's branch
asabil authored
87 for c in self.address_book.contacts:
88 if c.account == "@hotmail.com":
89 print "Fetching space of : %s with cid %s\n" % (c.display_name, c.cid)
90 self.spaces_service.get_contact_card(c)
91
9e686e1 @asabil - Conversations are usable now
asabil authored
92 if len(contacts) == 0:
7544026 @asabil - Merged jprieur's branch
asabil authored
93 print "No online contacts"
9e686e1 @asabil - Conversations are usable now
asabil authored
94 return True
95 else:
96 for contact in contacts:
daab162 @asabil - Merged jprieur's branch
asabil authored
97 if contact.account == "johann.prieur@gmail.com":
9e686e1 @asabil - Conversations are usable now
asabil authored
98 print "Inviting %s for a conversation" % contact.display_name
59c2d87 @asabil - Added the SwitchboardManager
asabil authored
99 self.conv = pymsn.Conversation(self, [contact])
100 AnnoyingConversation(self.conv)
9e686e1 @asabil - Conversations are usable now
asabil authored
101 return False
ebc2c89 @asabil - Added initial switchboard protocol implementation
asabil authored
102
971ccb2 @asabil - Started client implementation
asabil authored
103 def main():
104 import sys
105 import getpass
106 import signal
b2f4ebb @asabil - Changed the Event notification API.
asabil authored
107
41a2c90 @asabil - Fixed GNet protocol/HTTP.py http proxy authentication support
asabil authored
108 if "--http" in sys.argv:
109 http_mode = True
110 sys.argv.remove('--http')
111 else:
112 http_mode = False
971ccb2 @asabil - Started client implementation
asabil authored
113
114 if len(sys.argv) < 2:
115 account = raw_input('Account: ')
116 else:
117 account = sys.argv[1]
b2f4ebb @asabil - Changed the Event notification API.
asabil authored
118
971ccb2 @asabil - Started client implementation
asabil authored
119 if len(sys.argv) < 3:
120 passwd = getpass.getpass('Password: ')
121 else:
122 passwd = sys.argv[2]
123
124 mainloop = gobject.MainLoop(is_running=True)
125
126 def quit():
127 mainloop.quit()
128
129 def sigterm_cb():
130 gobject.idle_add(quit)
131
132 signal.signal(signal.SIGTERM, sigterm_cb)
133
41a2c90 @asabil - Fixed GNet protocol/HTTP.py http proxy authentication support
asabil authored
134 n = Client((account, passwd), quit, http_mode)
971ccb2 @asabil - Started client implementation
asabil authored
135
136 while mainloop.is_running():
137 try:
138 mainloop.run()
139 except KeyboardInterrupt:
140 quit()
141
142 if __name__ == '__main__':
143 main()
Something went wrong with that request. Please try again.