diff options
author | yvesf <yvesf@d0e8fea9-7529-0410-93fb-d39fd5b9c1dd> | 2009-05-27 21:45:23 +0000 |
---|---|---|
committer | yvesf <yvesf@d0e8fea9-7529-0410-93fb-d39fd5b9c1dd> | 2009-05-27 21:45:23 +0000 |
commit | 594699e711200eba92bc9fe7a0bedd39270b2768 (patch) | |
tree | 846b64860aa353214d9fcbe41f6a421f34d12327 | |
parent | fd19c29d708e95ccddfcff83d4206bc5bfdb82ee (diff) | |
download | omegle-594699e711200eba92bc9fe7a0bedd39270b2768.tar.gz omegle-594699e711200eba92bc9fe7a0bedd39270b2768.zip |
blah
git-svn-id: http://xapek.org/svn/common/omegle@1018 d0e8fea9-7529-0410-93fb-d39fd5b9c1dd
-rw-r--r-- | omegle.py | 44 | ||||
-rw-r--r-- | proxy.py | 15 |
2 files changed, 45 insertions, 14 deletions
@@ -3,6 +3,7 @@ import httplib import urllib import time import json +import logging from threading import Thread, Lock class Timer(Thread): @@ -38,6 +39,8 @@ class OmegleChat(object): self.timer = Timer(self.events, poll_interval) + self.logger = logging.getLogger(__name__ + self.__class__.__name__) + def start(self): self.conn_lock.acquire() self.conn.request("POST", "/start", {}, OmegleChat.headers) @@ -47,8 +50,9 @@ class OmegleChat(object): id=body.split("\"") if id.__len__() == 3: self.id = id[1] - print "Connected, id=%s" % self.id + self.logger.info("Connected id=%s" % self.id) else: + self.logger.error("Bad response: %s" % body) raise Exception("Bad response: %s" % body) #Poll events self.timer.start() @@ -79,6 +83,7 @@ class OmegleChat(object): conn.close() def send(self,msg): + msg = unicode(msg) self.conn_lock.acquire() self.conn.request("POST", "/send", @@ -88,6 +93,7 @@ class OmegleChat(object): self.conn_lock.release() body = r.read() if body != "win": + self.logger.error("/send; Bad response %s" % body) raise Exception("/send; Bad response %s" % body) def typing(self): @@ -100,14 +106,29 @@ class OmegleChat(object): self.conn_lock.release() body = r.read() if body != "win": + self.logger.error("/typing; Bad response %s" % body) raise Exception("/typing; Bad response %s" % body) + def stopped_typing(self): + self.conn_lock.acquire() + self.conn.request("POST", + "/stoppedtyping", + urllib.urlencode({'id':self.id}), + OmegleChat.headers) + r=self.conn.getresponse() + self.conn_lock.release() + body = r.read() + if body != "win": + self.logger.error("/stoppedtyping; Bad response %s" % body) + raise Exception("/stoppedtyping; Bad response %s" % body) + + def dispatch_event(self,conn,body): try: - data_set=json.read(body) + data_set=json.read(unicode(body)) if not data_set: - print "No Data received" + self.logger.debug("event: no data received") return for data in data_set: if data[0] == "typing": @@ -119,24 +140,29 @@ class OmegleChat(object): elif data[0] == "strangerDisconnected": self.timer.stop() self.on_disconnect() + elif data[0] == "stoppedTyping": + self.on_stopped_typing() elif data[0] == "waiting": pass #unhandled else: - print "Unknown JSON Data: %s" % body + self.logger.error("Unknown JSON Data: %s" % body) except json.ReadException: - print "Json ReadException. Body: %s" % body + self.logger.error("Json ReadException. Body: %s" % body) def on_message(self,message): - print "<<< %s" % message + self.logger.info("<<< %s" % message) def on_connect(self): - print "Connected" + self.logger.info("Connection confirmed") def on_typing(self): - print "Stranger is typing" + self.logger.info("Stranger is typing") + def on_stopped_typing(self): + self.logger.info("Stranger stopped typing") def on_disconnect(self): - print "Stranger Disconnectet" + self.logger.info("Stranger Disconnectet") if __name__ == "__main__": + logging.basicConfig(level=logging.INFO) print "Lets chat. Type \"quit\" to disconnect" chat = OmegleChat() chat.start() @@ -1,5 +1,5 @@ from omegle import OmegleChat -import sys +import sys, logging class OmegleProxyChat(OmegleChat): @@ -11,17 +11,22 @@ class OmegleProxyChat(OmegleChat): self.partner = partner def on_message(self,message): - print "%s: %s" %(self.name, message) + print "[MSG] %s: %s" %(self.name, message) self.partner.send(message) def on_connect(self): - print "%s Connected" % self.name + print "[EVT] %s Connection confirmed" % self.name def on_typing(self): - print "%s is typing" % self.name + print "[EVT] %s is typing" % self.name self.partner.typing() + def on_stopped_typing(self): + print "[EVT] %s stopped typing" % self.name + self.partner.stopped_typing() def on_disconnect(self): - print "%s disconnect" % self.name + print "[EVT] %s disconnect" % self.name self.partner.disconnect() +logging.basicConfig(level=logging.DEBUG) + A=OmegleProxyChat("A") B=OmegleProxyChat("B") |