def login(self, username, password): data = {'email': username, 'passwd': password} resp = RequestUtil.doPost(url=AojApi.getUrl('login'), data=data) jdata = json.loads(resp.text) if jdata['code'] == 0 and jdata['response']['message'] == 'success': return True else: PrintUtil.error(jdata['errorMessage']) return False
def login(self, username, password): # 验证码识别率较低..索性尝试5次 tryloginTime = 5 while (tryloginTime > 0): resp = RequestUtil.doPost(url=AojApi.getUrl('login'), data=self.getLoginData( username, password)) soup = BeautifulSoup(resp.text, "lxml") divlist = soup.find_all('div', class_='user') if len(divlist) > 3: info = divlist[3].font.string if info != "验证码有误": PrintUtil.error(info) return False else: return True tryloginTime = tryloginTime - 1 if tryloginTime <= 0: PrintUtil.error("oooops...验证码识别失败,再试试?")
def submitCode(self, code, pid): subData = { 'answer': code, 'id': pid, 'type': globalVar.BASE_CONF.get('contest', 'ctype') } resp = RequestUtil.doPost(AojApi.getUrl('submitCode'), subData) # {"id":"125","result":"Wrong Answer.","score":0,"time":"21:34:35"} try: jdata = json.loads(resp.text) result = jdata['result'] score = jdata['score'] time = jdata['time'] color = "red" if result == "Answer Correct.": color = "green" print( termcolor.colored(result, color) + '\n' + "得分:" + termcolor.colored(str(score), color) + '\n' + "提交时间:" + termcolor.colored(time, color)) except: PrintUtil.error('oops!提交出错了,请重新提交. *_*.')