Skip to content

Commit

Permalink
#411: add a workaround for the scores surrounded by \( \) in AtCoder
Browse files Browse the repository at this point in the history
  • Loading branch information
kmyk committed Apr 22, 2019
1 parent 55591e1 commit 92d9a37
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 7 additions & 1 deletion onlinejudge/service/atcoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,13 @@ def _AtCoderProblemContent_parse_score(soup: bs4.BeautifulSoup) -> Optional[int]
task_statement = soup.find('div', id='task-statement')
p = task_statement.find('p') # first
if p is not None and p.text.startswith('配点 : '):
return int(utils.remove_suffix(utils.remove_prefix(p.text, '配点 : '), ' 点'))
score = utils.remove_suffix(utils.remove_prefix(p.text, '配点 : '), ' 点')
try:
return int(score)
except ValueError:
# some problems have scores like "<p>配点 : \(100\) 点</p>", not "<p>配点 : 100 点</p>"
# example: https://atcoder.jp/contests/wupc2019/tasks/wupc2019_a
pass
return None


Expand Down
7 changes: 7 additions & 0 deletions tests/service_atcoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ def test_get_score(self):
self.assertEqual(AtCoderProblem.from_url('https://atcoder.jp/contests/future-contest-2018-final/tasks/future_contest_2018_final_a').get_score(), 50000000)
self.assertEqual(AtCoderProblem.from_url('https://atcoder.jp/contests/abc001/tasks/abc001_4').get_score(), None)

def test_get_score_latex(self):
"""
:sa: https://github.com/kmyk/online-judge-tools/issues/411
"""

self.assertIsNone(AtCoderProblem.from_url('https://atcoder.jp/contests/wupc2019/tasks/wupc2019_a').get_score())

def test_iterate_submissions(self):
problem = AtCoderProblem.from_url('https://atcoder.jp/contests/abc119/tasks/abc119_c')
submissions = problem.iterate_submissions()
Expand Down

0 comments on commit 92d9a37

Please sign in to comment.