· 8 years ago · Jun 03, 2018, 12:14 PM
1 #gtalk.py
2
3import xmpp
4
5# Google Talk constants
6FROM_GMAIL_ID = "username@gmail.com"
7GMAIL_PASS = "secret passwd"
8GTALK_SERVER = "gmail.com"
9
10jid=xmpp.protocol.JID(FROM_GMAIL_ID)
11C=xmpp.Client(jid.getDomain(),debug=[])
12
13if not C.connect((GTALK_SERVER,5222)):
14 raise IOError('Can not connect to server.')
15if not C.auth(jid.getNode(),GMAIL_PASS):
16 raise IOError('Can not auth with server.')
17
18C.sendInitPresence(requestRoster=1)
19
20def myPresenceHandler(con, event):
21 if event.getType() == 'unavailable':
22 print event.getFrom().getStripped()
23
24C.RegisterHandler('presence', myPresenceHandler)
25while C.Process(1):
26 pass