-
Notifications
You must be signed in to change notification settings - Fork 2
/
poj_bot.py
29 lines (24 loc) · 868 Bytes
/
poj_bot.py
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
import urllib
import urllib2
import cookielib
class POJBot:
cookiejar = cookielib.CookieJar()
opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar))
def __init__(self):
return None
def login(self, username, password):
loginurl = 'http://poj.org/login'
postdata = urllib.urlencode({
'user_id1':username,
'password1':password })
self.opener.open(loginurl, postdata)
def logout(self):
logouturl = 'http://poj.org/login?action=logout'
self.opener.open(logouturl)
def submit_code(self, pid, code):
submiturl = 'http://poj.org/submit'
postdata = urllib.urlencode({
'problem_id':1000,
'language':'0', #cpp
'source':code })
res = self.opener.open(submiturl, postdata)