def result_parse(self, response): result = Result() if response is None or response.status_code != 200: result.status = Result.Status.STATUS_SUBMIT_FAILED return result website_data = response.text soup = BeautifulSoup(website_data, 'lxml') if soup.find('table', attrs={ 'id': 'result-tab' }).find('tr', attrs={'class': 'evenrow'}) is None: result.status = Result.Status.STATUS_SUBMIT_FAILED return result line = soup.find('table', attrs={ 'id': 'result-tab' }).find('tr', attrs={ 'class': 'evenrow' }).find_all('td') if line: result.origin_run_id = line[0].string result.verdict = line[4].string result.execute_time = line[6].string result.execute_memory = line[5].string result.status = Result.Status.STATUS_RESULT else: result.status = Result.Status.STATUS_SUBMIT_FAILED return result
def result_parse(self, response): if response is None or response.status_code != 200 or response.text is None: result = Result() result.status = Result.Status.STATUS_SUBMIT_FAILED return result soup = BeautifulSoup(response.text, 'lxml') table = soup.find('table') tag = None if table: tag = table.find_all('tr') if tag: children_tag = tag[-1].find_all('td') if len(children_tag) > 9: result = Result() result.origin_run_id = children_tag[0].string result.verdict = '' for item in children_tag[4].stripped_strings: result.verdict += str(item) + ' ' result.verdict = result.verdict.strip(' ') result.execute_time = children_tag[5].string result.execute_memory = children_tag[6].string result.status = Result.Status.STATUS_RESULT return result result = Result() result.status = Result.Status.STATUS_SUBMIT_FAILED return result
def get_result_by_url(self, url): result = Result() try: res = self.request.get(url=url) soup = BeautifulSoup(res.text, 'lxml') line = soup.find('table', attrs={'class': 'a'}).find('tr', attrs={'align': 'center'}).find_all('td') if line is not None: result.origin_run_id = line[0].string result.verdict = line[3].string result.execute_time = line[5].string result.execute_memory = line[4].string return result except: pass return None
def test_result(self): result = Result() result.execute_memory = '128 MB' result.execute_time = '1000 MS' result.origin_run_id = '1' result.verdict = 'Accepted' self.assertDictEqual( result.__dict__, { 'execute_memory': '128 MB', 'execute_time': '1000 MS', 'origin_run_id': '1', 'status': None, 'info': None, 'verdict': 'Accepted', 'verdict_code': Result.VerdictCode.STATUS_RUNNING })
def result_parse(self, response): result = Result() if response is None or response.status_code != 200: result.status = Result.Status.STATUS_SUBMIT_FAILED return result soup = BeautifulSoup(response.text, 'lxml') line = soup.find('table', attrs={'class': 'a'}).find('tr', attrs={'align': 'center'}).find_all('td') if line is not None: result.origin_run_id = line[0].string result.verdict = line[3].string result.execute_time = line[5].string result.execute_memory = line[4].string result.status = Result.Status.STATUS_RESULT else: result.status = Result.Status.STATUS_SUBMIT_FAILED return result
def result_parse(self, response): result = Result() if response is None or response.status_code != 200: result.status = Result.Status.STATUS_SUBMIT_FAILED return result website_data = response.text site_data = json.loads(website_data) submission_record = site_data['submissionRecord'] result.origin_run_id = str(submission_record['judgeId']) result.verdict = self._judge_static_string[int( submission_record['status'])] result.execute_time = str( format(float(submission_record['cpuTime']) / float(100), '.2f')) + ' s' result.execute_memory = str(submission_record['memory']) + ' KB' result.status = Result.Status.STATUS_RESULT return result
def result_parse_by_rid(self, response, rid): result = Result() if response is None or response.status_code != 200: result.status = Result.Status.STATUS_SUBMIT_FAILED return result, False website_data = response.text soup = BeautifulSoup(website_data, 'lxml') lines = soup.find_all('tr', attrs={'onmouseover': 'hl(this);'}) for line in lines: tag_tds = line.find_all('td') if len(tag_tds) == 9 and int(tag_tds[0].get_text()) == int(rid): result.origin_run_id = tag_tds[0].string result.verdict = tag_tds[2].string result.execute_time = tag_tds[5].string result.execute_memory = tag_tds[6].string result.status = Result.Status.STATUS_RESULT return result, True result.status = Result.Status.STATUS_SUBMIT_FAILED return result, False
def result_parse(self, response): result = Result() if response is None or response.status_code != 200: result.status = Result.Status.STATUS_SUBMIT_FAILED return result website_data = response.text soup = BeautifulSoup(website_data, 'lxml') lines = soup.find('tr', attrs={'onmouseover': 'hl(this);'}) if lines is not None: line = lines.find_all('td') if line is not None: result.origin_run_id = line[0].string result.verdict = line[2].string result.execute_time = line[5].string result.execute_memory = line[6].string result.status = Result.Status.STATUS_RESULT else: result.status = Result.Status.STATUS_SUBMIT_FAILED return result