summaryrefslogtreecommitdiff
path: root/test.py
diff options
context:
space:
mode:
Diffstat (limited to 'test.py')
-rw-r--r--test.py30
1 files changed, 29 insertions, 1 deletions
diff --git a/test.py b/test.py
index 19564bb..1e9d6c2 100644
--- a/test.py
+++ b/test.py
@@ -2,6 +2,7 @@ import sys
import httplib
import urllib
import time
+import json
from threading import Thread, Lock
class Timer(Thread):
@@ -103,7 +104,33 @@ class OmegleChat(object):
def on_event(self,conn,body):
- print "Event: %s" % body
+ try:
+ data_set=json.read(body)
+ for data in data_set:
+ if data[0] == "typing":
+ self.on_typing()
+ elif data[0] == "gotMessage" and data.__len__() == 2:
+ self.on_message(data[1])
+ elif data[0] == "connected":
+ self.on_connect()
+ elif data[0] == "strangerDisconnected":
+ self.timer.stop()
+ self.on__disconnect()
+ elif data[0] == "waiting":
+ pass #unhandled
+ else:
+ print "Unknown JSON Data: %s" % body
+ except json.ReadException:
+ print "Json ReadException. Body: %s" % body
+
+ def on_message(self,message):
+ print "<<< %s" % message
+ def on_connect(self):
+ print "Connected"
+ def on_typing(self):
+ print "Stranger typing"
+ def on_disconnect(self):
+ print "Stranger Disconnectect"
chat = OmegleChat()
chat.start()
@@ -118,5 +145,6 @@ while 1==1:
chat.disconnect()
break
else:
+ print ">>> %s" % cmd
chat.send(cmd)