diff options
author | yvesf <yvesf@d0e8fea9-7529-0410-93fb-d39fd5b9c1dd> | 2009-05-27 19:25:17 +0000 |
---|---|---|
committer | yvesf <yvesf@d0e8fea9-7529-0410-93fb-d39fd5b9c1dd> | 2009-05-27 19:25:17 +0000 |
commit | a70284854cff79799e548179f73ce72a99f8e633 (patch) | |
tree | 2bfe11e854d7444b597bd7d908e149553c331fad | |
parent | 9a313ef854e588420ec52611ea014684aab5f0da (diff) | |
download | omegle-a70284854cff79799e548179f73ce72a99f8e633.tar.gz omegle-a70284854cff79799e548179f73ce72a99f8e633.zip |
omegle test
git-svn-id: http://xapek.org/svn/common/omegle@1011 d0e8fea9-7529-0410-93fb-d39fd5b9c1dd
-rw-r--r-- | test.py | 64 |
1 files changed, 64 insertions, 0 deletions
@@ -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) + |