3
# Copyright (c) 2001-2009 Twisted Matrix Laboratories.
4
# See LICENSE for details.
7
from twisted.internet import reactor
8
from twisted.internet.protocol import ClientFactory
9
from twisted.words.protocols import msn
10
from twisted.python import log
16
This example connects to the MSN chat service and
17
prints out information about all the users on your
18
contact list (both online and offline).
20
The main aim of this example is to demonstrate
21
the connection process.
27
def _createNotificationFac():
28
fac = msn.NotificationFactory()
29
fac.userHandle = USER_HANDLE
30
fac.password = PASSWORD
31
fac.protocol = Notification
34
class Dispatch(msn.DispatchClient):
37
msn.DispatchClient.__init__(self)
38
self.userHandle = USER_HANDLE
40
def gotNotificationReferral(self, host, port):
41
self.transport.loseConnection()
42
reactor.connectTCP(host, port, _createNotificationFac())
44
class Notification(msn.NotificationClient):
46
def loginFailure(self, message):
47
print 'Login failure:', message
49
def listSynchronized(self, *args):
50
contactList = self.factory.contacts
51
print 'Contact list has been synchronized, number of contacts = %s' % len(contactList.getContacts())
52
for contact in contactList.getContacts().values():
53
print 'Contact: %s' % (contact.screenName,)
54
print ' email: %s' % (contact.userHandle,)
56
for group in contact.groups:
57
print ' - %s' % contactList.groups[group]
60
if __name__ == '__main__':
61
USER_HANDLE = raw_input("Email (passport): ")
62
PASSWORD = getpass.getpass()
63
log.startLogging(sys.stdout)
64
_dummy_fac = ClientFactory()
65
_dummy_fac.protocol = Dispatch
66
reactor.connectTCP('messenger.hotmail.com', 1863, _dummy_fac)