def submit(self): if self.submission.retry_count > 10: return if self.submission.status == JudgeRequest.status['PENDING'] or \ self.submission.status == JudgeRequest.status['SEND_FOR_JUDGE_ERROR']: account = self.choose_account(self.submission.problem.remote_oj) # print('account', account, self.submission.problem.remote_oj) if not account: self.retry() raise SubmissionException success_submit = Controller.submit_code( self.submission.problem.remote_oj, Account(username=account.username, password=account.password), self.submission.source, self.submission.language, self.submission.problem.remote_id) # print('success_submit', success_submit) if success_submit: result = Controller.get_result( self.submission.problem.remote_oj, Account(username=account.username, password=account.password), self.submission.problem.remote_id) # print('result', result) # 结果返回有误 if not result: if self.submission.status == JudgeRequest.status[ 'SEND_FOR_JUDGE_ERROR']: self.submission.status = JudgeRequest.status['RETRY'] else: self.submission.status = JudgeRequest.status[ 'SEND_FOR_JUDGE_ERROR'] self.release_account(account.id) self.retry() raise Submission self.submission.remote_run_id = result.origin_run_id self.submission.judge_result = result.verdict self.submission.execute_memory = result.execute_memory self.submission.execute_time = result.execute_time self.submission.save() if self.waiting_for_judge(): print('submit_success') self.update_statistic() else: self.submission.status = JudgeRequest.status['RETRY'] self.release_account(account.id) self.retry() raise SubmissionException else: # 提交失败 if self.submission.status == JudgeRequest.status[ 'SEND_FOR_JUDGE_ERROR']: self.submission.status = JudgeRequest.status['RETRY'] else: self.submission.status = JudgeRequest.status[ 'SEND_FOR_JUDGE_ERROR'] self.retry() self.release_account(account.id) raise SubmissionException self.release_account(account.id)
def get_raw(remote_oj, remote_id): problem = Controller(remote_oj).get_problem(remote_id, account=Account('robot4test', 'robot4test')) if problem and problem.status: problem.status = problem.status.value return '<xmp>' + str( json.dumps(problem.__dict__, sort_keys=True, indent=4)) + '</xmp>' return 'No Such OJ'
def test_get_problem_with_proxies(self): account = Account('robot4test', 'robot4test') WUST = Controller('WUST') self.assertIsNotNone(WUST) problem = WUST.get_problem(account=account, pid='1039') print(problem.__dict__) self.assertIsNotNone(problem) WUST = Controller('WUST', proxies='socks5://127.0.0.1:1086') self.assertIsNotNone(WUST) problem = WUST.get_problem(account=account, pid='1039') print(problem.__dict__) self.assertIsNotNone(problem)
def submit(): source_code = request.files['source_code'] if request.form.get('remote_oj') and request.form.get('language') and request.form.get( 'remote_id') and source_code: remote_oj = request.form['remote_oj'] remote_id = request.form['remote_id'] language = request.form['language'] ans = False tries = 3 print('start') account = Account('robot4test', 'robot4test') while ans is False and tries > 0: tries -= 1 controller = Controller(str(remote_oj)) ans = controller.submit_code(pid=remote_id, account=account, code=source_code.read(), language=language) account.set_cookies(controller.get_cookies()) if ans is False: return "SUBMIT FAILED" controller = Controller(remote_oj) result = controller.get_result(account=account, pid=remote_id) account.set_cookies(controller.get_cookies()) print('end') tries = 5 while result.status == Result.Status.STATUS_RESULT and tries > 0: time.sleep(2) if Controller(remote_oj).is_waiting_for_judge(result.verdict): result = Controller(remote_oj).get_result_by_rid_and_pid(rid=result.origin_run_id, pid=remote_id) else: break tries -= 1 if result.status == Result.Status.STATUS_RESULT: return str(result.__dict__) return result.status.name return "Error"
def test_get_problem(self): account = Account('robot4test', 'robot4test') POJ = Controller('POJ') self.assertIsNotNone(POJ) POJ.get_result(account=account, pid='1379') POJ.get_problem(account=account, pid='1379')
def test_get_problem(self): hdu = Controller('HDU') account = Account('robot4test', 'robot4test') self.assertIsNotNone(hdu) hdu.get_problem(account=account, pid='1001')
def problem(remote_oj, remote_id): problem = Controller(remote_oj).get_problem(remote_id, account=Account('robot4test', 'robot4test')) if problem.status == Problem.Status.STATUS_CRAWLING_SUCCESS: return problem.html return problem.status.name
def language(remote_oj): return json.dumps({ 'languages': Controller(remote_oj).find_language(account=Account('robot4test', 'robot4test')) })
def test_get_problem(self): account = Account('robot4test', 'robot4test') Aizu = Controller('Aizu') self.assertIsNotNone(Aizu) # Aizu.get_result(account=account,pid='0001') Aizu.get_problem(account=account, pid='0001')
post_code = """// 2052 #include <cstdio> #include <cstring> #include <algorithm> #include <iostream> #include <set> using namespace std; int main(){ int n; cin >> n; int a,b; int ans = 0; while(n--){ cin >> a >> b; while(ans>=a) a+=b; ans = a; } cout << ans << endl; return 0; } """ if __name__ == '__main__': account = Account('robot4test', 'robot4test') result = Controller('codeforces').submit_code(pid='879A', account=account, code=post_code, language='50') print(result)
def test_get_problem(self): account = Account('robot4test', 'robot4test') FZU = Controller('FZU') self.assertIsNotNone(FZU) FZU.get_result(account=account, pid='1039') FZU.get_problem(account=account, pid='1039')
def test_get_problem(self): account = Account('robot4test', 'robot4test') WUST = Controller('WUST') self.assertIsNotNone(WUST) problem = WUST.get_problem(account=account, pid='1039') self.assertIsNotNone(problem)