From 4698adc0927976fb854120c83494a6af877081fd Mon Sep 17 00:00:00 2001 From: yvesf Date: Wed, 27 May 2009 20:14:11 +0000 Subject: foobar git-svn-id: http://xapek.org/svn/common/omegle@1013 d0e8fea9-7529-0410-93fb-d39fd5b9c1dd --- test.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) 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) -- cgit v1.2.1