summaryrefslogtreecommitdiff
path: root/test.py
diff options
context:
space:
mode:
Diffstat (limited to 'test.py')
-rw-r--r--test.py64
1 files changed, 64 insertions, 0 deletions
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)
+