forked from kuri65536/python-for-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsay_chat.py
More file actions
51 lines (40 loc) · 1.29 KB
/
Copy pathsay_chat.py
File metadata and controls
51 lines (40 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""Say chat messages aloud as they are received."""
__author__ = 'Damon Kohler <damonkohler@gmail.com>'
__copyright__ = 'Copyright (c) 2009, Google Inc.'
__license__ = 'Apache License, Version 2.0'
import android
import xmpp
_SERVER = 'talk.google.com', 5223
def log(droid, message):
print message
self.droid.ttsSpeak(message)
class SayChat(object):
def __init__(self):
self.droid = android.Android()
username = self.droid.dialogGetInput('Username').result
password = self.droid.dialogGetInput('Password').result
jid = xmpp.protocol.JID(username)
self.client = xmpp.Client(jid.getDomain(), debug=[])
self.client.connect(server=_SERVER)
self.client.RegisterHandler('message', self.message_cb)
if not self.client:
log('Connection failed!')
return
auth = self.client.auth(jid.getNode(), password, 'botty')
if not auth:
log('Authentication failed!')
return
self.client.sendInitPresence()
def message_cb(self, session, message):
jid = xmpp.protocol.JID(message.getFrom())
username = jid.getNode()
text = message.getBody()
self.droid.ttsSpeak('%s says %s' % (username, text))
def run(self):
try:
while True:
self.client.Process(1)
except KeyboardInterrupt:
pass
saychat = SayChat()
saychat.run()