diff options
-rw-r--r-- | test.py | 44 |
1 files changed, 23 insertions, 21 deletions
@@ -75,7 +75,7 @@ class OmegleChat(object): OmegleChat.headers) r=conn.getresponse() body=r.read() - self.on_event(conn,body) + self.dispatch_event(conn,body) conn.close() def send(self,msg): @@ -103,7 +103,7 @@ class OmegleChat(object): raise Exception("/typing; Bad response %s" % body) - def on_event(self,conn,body): + def dispatch_event(self,conn,body): try: data_set=json.read(body) for data in data_set: @@ -128,23 +128,25 @@ class OmegleChat(object): def on_connect(self): print "Connected" def on_typing(self): - print "Stranger typing" + print "Stranger is typing" def on_disconnect(self): - print "Stranger Disconnectect" - -chat = OmegleChat() -chat.start() - -while 1==1: - try: - cmd=sys.stdin.readline().strip() - except KeyboardInterrupt: - chat.disconnect() - sys.exit(0) - if cmd=="quit": - chat.disconnect() - break - else: - print ">>> %s" % cmd - chat.send(cmd) - + print "Stranger Disconnectet" + + +if __name__ == "__main__": + print "Lets chat. Type \"quit\" to disconnect" + chat = OmegleChat() + chat.start() + while 1==1: + try: + cmd=sys.stdin.readline().strip() + except KeyboardInterrupt: + chat.disconnect() + break + if cmd=="quit": + chat.disconnect() + break + else: + print ">>> %s" % cmd + chat.send(cmd) + |