Skip to content

Commit 3905f48

Browse files
committed
feat(problem): Add support for gym problems
1 parent 9de27b3 commit 3905f48

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

codeforces/problem.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
CODEFORCES_URL = "https://codeforces.com"
1111

1212

13-
def get_info(contest_id, index, lang='en'):
13+
def get_info(contest_id, index, gym=False, lang='en'):
1414
"""
1515
Get info for a contest problem.
1616
@@ -23,6 +23,9 @@ def get_info(contest_id, index, lang='en'):
2323
Usually a letter of a letter, followed by a digit, that
2424
represent a problem index in a contest. It can be seen in
2525
problem URL. For example: /contest/566/**A**
26+
gym: bool
27+
If true gym problem is returned otherwise regular problem is
28+
returned.
2629
2730
Returns
2831
-------
@@ -36,10 +39,16 @@ def get_info(contest_id, index, lang='en'):
3639
Sample tests given for the problem.
3740
3841
"""
39-
problem_url = os.path.join(
40-
CODEFORCES_URL,
41-
"contest/%d/problem/%s?lang=%s" % (contest_id, index, lang)
42-
)
42+
if gym:
43+
problem_url = os.path.join(
44+
CODEFORCES_URL,
45+
"gym/%d/problem/%s?lang=%s" % (contest_id, index, lang)
46+
)
47+
else:
48+
problem_url = os.path.join(
49+
CODEFORCES_URL,
50+
"contest/%d/problem/%s?lang=%s" % (contest_id, index, lang)
51+
)
4352

4453
with urllib.request.urlopen(problem_url) as res:
4554
soup = BeautifulSoup(res.read(), 'html.parser')
@@ -49,8 +58,13 @@ def get_info(contest_id, index, lang='en'):
4958
time_limit = soup.find_all("div", class_="time-limit")[0].text[19:]
5059
memory_limit = soup.find_all("div", class_="memory-limit")[0].text[21:]
5160

52-
inputs = [i.pre.text.lstrip('\n') for i in soup.find_all("div", class_="input")]
53-
outputs = [i.pre.text.lstrip('\n') for i in soup.find_all("div", class_="output")]
61+
inputs = [
62+
i.pre.text.lstrip('\n') for i in soup.find_all("div", class_="input")
63+
]
64+
65+
outputs = [
66+
i.pre.text.lstrip('\n') for i in soup.find_all("div", class_="output")
67+
]
5468

5569
sample_tests = zip(inputs, outputs)
5670

0 commit comments

Comments
 (0)