Example #1
0
    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
Example #2
0
File: poj.py Project: KinKir/spider
 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
Example #3
0
    def get_result_by_rid_and_pid(self, rid, pid):
        if not self._oj:
            return Result(Result.VerdictCode.STATUS_SUBMIT_FAILED)

        result = self._oj.get_result_by_rid_and_pid(rid, pid)
        if result is not None:
            if self._oj.is_accepted(result.verdict):
                result.verdict_code = Result.VerdictCode.STATUS_ACCEPTED
            elif self._oj.is_running(result.verdict):
                result.verdict_code = Result.VerdictCode.STATUS_RUNNING
            elif self._oj.is_compile_error(result.verdict):
                result.verdict_code = Result.VerdictCode.STATUS_COMPILE_ERROR
            else:
                result.verdict_code = Result.VerdictCode.STATUS_RESULT_ERROR
            result.execute_time = self._space_and_enter_strip(
                result.execute_time)
            result.execute_memory = self._space_and_enter_strip(
                result.execute_memory)
            return result
        return Result(Result.VerdictCode.STATUS_SUBMIT_FAILED)
Example #4
0
    def get_result(self, account, pid, *args, **kwargs):
        if self.login_website(account, *args, **kwargs) is False:
            result = Result()
            result.status = Result.Status.STATUS_SUBMIT_FAILED
            return result

        request_url = 'http://codeforces.com/problemset/status?friends=on'
        self._browser.open(request_url)
        website_data = self._browser.response.page_source
        if website_data:
            soup = BeautifulSoup(website_data, 'lxml')
            tag = soup.find('table', attrs={'class': 'status-frame-datatable'})
            if tag:
                list_tr = tag.find_all('tr')
                for tr in list_tr:
                    if isinstance(
                            tr, element.Tag) and tr.get('data-submission-id'):
                        return self.get_result_by_url(
                            'http://codeforces.com/contest/' + pid[:-1] +
                            '/submission/' + tr.get('data-submission-id'))
        return Result(Result.Status.STATUS_SUBMIT_FAILED)
Example #5
0
 def submit_code(self, pid, account, code, language, **kwargs):
     if not self._oj:
         return None
     self._oj.set_cookies(account.cookies)
     if self._oj.submit_code(account=account,
                             code=code,
                             language=language,
                             pid=pid,
                             **kwargs):
         time.sleep(2)
         return self.get_result(account=account, pid=pid, **kwargs)
     else:
         return Result(Result.VerdictCode.STATUS_SUBMIT_FAILED)
Example #6
0
    def get_result(self, account, pid, **kwargs):

        if not self._oj:
            return Result(Result.VerdictCode.STATUS_SUBMIT_FAILED)
        self._oj.set_cookies(account.cookies)
        result = self._oj.get_result(account=account, pid=pid, **kwargs)
        if result is not None:
            if self._oj.is_accepted(result.verdict):
                result.verdict_code = Result.VerdictCode.STATUS_ACCEPTED
            elif self._oj.is_running(result.verdict):
                result.verdict_code = Result.VerdictCode.STATUS_RUNNING
            elif self._oj.is_compile_error(result.verdict):
                result.verdict_code = Result.VerdictCode.STATUS_COMPILE_ERROR
            else:
                result.verdict_code = Result.VerdictCode.STATUS_RESULT_ERROR
            result.execute_time = self._space_and_enter_strip(
                result.execute_time)
            result.execute_memory = self._space_and_enter_strip(
                result.execute_memory)

            return result
        return Result(Result.VerdictCode.STATUS_SUBMIT_FAILED)
Example #7
0
    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
Example #8
0
    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
Example #9
0
    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
Example #10
0
 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
Example #11
0
 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
         })
Example #12
0
 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