#!/usr/bin/env python
# This shows how to use MSN.py from a script
#
# Right now maybe MSN.py doesn't have a perfect interface but is usable for
# some quick scripts
import sys
import pypebrot.MSN
USER= 'someuser@hotmail.com'
PASSWD= 'password'
FRIEND= 'somefriend@hotmail.com'
INIT_STATE= 'NLN'
# Assign 1 for some debugging output
pypebrot.MSN.DEBUG= 0
# Subclass of MSN.Session for redefining some callbacks
class MyClass( pypebrot.MSN.Session ):
def selfStateChanged( self, state ):
print "I've changed my state"
def protoError( self, code ):
print '\nOops, Protocol error: %s - %s' % (code, pypebrot.MSN.ERRORS[code])
sys.exit()
def userOn( self, passport ):
print passport, "is connected"
# Let's salute some friend...
if passport == FRIEND and self.usersOnline[passport]['state'] == 'NLN':
chat= self.newChat( passport )
self.sendChatMsg( chat, 'Hi pal!' )
con= MyClass()
con.connect( USER, PASSWD, INIT_STATE )
# This will execute forever, maybe you would set some timeout
while 1:
con.step()
|