summaryrefslogtreecommitdiff
path: root/test.py
blob: 188d7dcc3adcf9976d40d216e5e663407b85375e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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)