From a70284854cff79799e548179f73ce72a99f8e633 Mon Sep 17 00:00:00 2001 From: yvesf Date: Wed, 27 May 2009 19:25:17 +0000 Subject: omegle test git-svn-id: http://xapek.org/svn/common/omegle@1011 d0e8fea9-7529-0410-93fb-d39fd5b9c1dd --- test.py | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 test.py (limited to 'test.py') diff --git a/test.py b/test.py new file mode 100644 index 0000000..188d7dc --- /dev/null +++ b/test.py @@ -0,0 +1,64 @@ +import sys +import httplib +import urllib + +headers = { + "Host" : "omegle.com", + "Content-type": "application/x-www-form-urlencoded; charset=utf-8", + "Accept": "application/json"} +class OmegleChat(object): + def __init__(self): + self.conn = httplib.HTTPConnection('www.omegle.com') + self.conn.set_debuglevel(100) + def start(self): + self.conn.request("POST", "/start", {}, headers) + r=self.conn.getresponse() + body=r.read() + id=body.split("\"") + if id.__len__() == 3: + self.id = id[1] + print "Connected, id=%s" % self.id + else: + raise Exception("Bad response: %s" % body) + self.events() + + def disconnect(self): + self.conn.request("POST", + "/disconnect", + urllib.urlencode({'id' : self.id}), + headers) + r = self.conn.getresponse() + print r.read() + + def events(self): + self.conn.request("POST", + "/events", + urllib.urlencode({'id' : self.id}), + headers) + r=self.conn.getresponse() + body=r.read() + print "Poll response: %s" % body + return body + + def send(self,msg): + self.conn.request("POST", + "/send", + urllib.urlencode({'id':self.id,'msg':msg}), + headers) + r=self.conn.getresponse() + print r.read() + +chat = OmegleChat() +chat.start() + +while 1==1: + cmd=sys.stdin.readline().strip() + if cmd=="": + print "Poll:" + chat.events() + elif cmd=="quit": + chat.disconnect() + break + else: + chat.send(cmd) + -- cgit v1.2.1