Skip to content

Commit 80bfa09

Browse files
Format Files
1 parent dce7363 commit 80bfa09

File tree

6 files changed

+26
-58
lines changed

6 files changed

+26
-58
lines changed

codeforces/api.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,13 @@
1111

1212
__all__ = ['call']
1313

14-
1514
CODEFORCES_API_URL = "https://codeforces.com/api/"
1615

1716

1817
def _generate_api_sig(method, args, secret):
1918
rand = "%06d" % secrets.randbelow(999999)
2019
url_args = urllib.parse.urlencode(sorted(args.items()))
21-
return rand + hashlib.sha512(
22-
("%s/%s?%s#%s" % (rand, method, url_args, secret)).encode('utf-8')
23-
).hexdigest()
20+
return rand + hashlib.sha512(("%s/%s?%s#%s" % (rand, method, url_args, secret)).encode('utf-8')).hexdigest()
2421

2522

2623
def call(method, key=None, secret=None, **kwargs):
@@ -56,10 +53,7 @@ def call(method, key=None, secret=None, **kwargs):
5653

5754
with requests.get(url, params=params) as res:
5855
if res.status_code == 404:
59-
data = {
60-
'status': 'FAILED',
61-
'comment': "%s: No such method" % method
62-
}
56+
data = {'status': 'FAILED', 'comment': "%s: No such method" % method}
6357
elif res.status_code in (429, 503):
6458
time.sleep(1)
6559
return call(method, key, secret, **kwargs)

codeforces/cf_run.py

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,37 +17,27 @@ def main(argv=None):
1717
parser = argparse.ArgumentParser()
1818

1919
parser.add_argument(
20-
'contestId',
21-
type=int,
22-
help=
23-
"Id of the contest. It is not the round number. It can be seen in contest URL."
24-
)
20+
'contestId', type=int, help="Id of the contest. It is not the round number. It can be seen in contest URL.")
2521

2622
parser.add_argument(
2723
'index',
2824
type=str,
29-
help=
30-
"A letter or a letter followed by a digit, that represent a problem index in a contest."
31-
)
25+
help="A letter or a letter followed by a digit, that represent a problem index in a contest.")
3226

33-
parser.add_argument(
34-
'program', type=str, help="Path to executable that needs to be tested")
27+
parser.add_argument('program', type=str, help="Path to executable that needs to be tested")
3528

3629
parser.add_argument(
3730
'-t',
3831
'--timeout',
3932
type=int,
4033
default=10,
41-
help=
42-
"Timeout for program in seconds, -1 for no time limit (default: 10)")
34+
help="Timeout for program in seconds, -1 for no time limit (default: 10)")
4335

4436
parser.add_argument(
4537
'-g',
4638
'--gym',
4739
action='store_true',
48-
help=
49-
"If true open gym contest instead of regular contest. (default: false)"
50-
)
40+
help="If true open gym contest instead of regular contest. (default: false)")
5141

5242
if argv:
5343
args = parser.parse_args(argv)
@@ -56,8 +46,7 @@ def main(argv=None):
5646

5747
args.timeout = None if args.timeout == -1 else args.timeout
5848

59-
title, time_limit, memory_limit, sample_tests = problem.get_info(
60-
args.contestId, args.index, gym=args.gym)
49+
title, time_limit, memory_limit, sample_tests = problem.get_info(args.contestId, args.index, gym=args.gym)
6150

6251
print(title)
6352
print("time limit per test:", time_limit)

codeforces/problem.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,9 @@ def get_info(contest_id, index, gym=False, lang='en'):
3939
4040
"""
4141
if gym:
42-
problem_url = urllib.parse.urljoin(
43-
CODEFORCES_URL,
44-
"gym/%d/problem/%s" % (contest_id, index)
45-
)
42+
problem_url = urllib.parse.urljoin(CODEFORCES_URL, "gym/%d/problem/%s" % (contest_id, index))
4643
else:
47-
problem_url = urllib.parse.urljoin(
48-
CODEFORCES_URL,
49-
"contest/%d/problem/%s" % (contest_id, index)
50-
)
44+
problem_url = urllib.parse.urljoin(CODEFORCES_URL, "contest/%d/problem/%s" % (contest_id, index))
5145

5246
with requests.get(problem_url, params={'lang': lang}) as res:
5347
soup = BeautifulSoup(res.text, 'html.parser')
@@ -57,13 +51,9 @@ def get_info(contest_id, index, gym=False, lang='en'):
5751
time_limit = soup.find_all("div", class_="time-limit")[0].text[19:]
5852
memory_limit = soup.find_all("div", class_="memory-limit")[0].text[21:]
5953

60-
inputs = [
61-
i.pre.get_text('\n').lstrip('\n') for i in soup.find_all("div", class_="input")
62-
]
54+
inputs = [i.pre.get_text('\n').lstrip('\n') for i in soup.find_all("div", class_="input")]
6355

64-
outputs = [
65-
i.pre.get_text('\n') for i in soup.find_all("div", class_="output")
66-
]
56+
outputs = [i.pre.get_text('\n').lstrip('\n') for i in soup.find_all("div", class_="output")]
6757

6858
sample_tests = zip(inputs, outputs)
6959

codeforces/submission.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ def get_submission(submission_id):
2626
csrf_token = soup.find('meta', attrs={'name': 'X-Csrf-Token'})['content']
2727

2828
res = sess.post(
29-
'https://codeforces.com/data/submitSource',
30-
{'submissionId': submission_id, 'csrf_token': csrf_token},
31-
headers={'X-Csrf-Token': csrf_token}
32-
)
29+
'https://codeforces.com/data/submitSource', {
30+
'submissionId': submission_id,
31+
'csrf_token': csrf_token
32+
},
33+
headers={'X-Csrf-Token': csrf_token})
3334

3435
return json.loads(res.text)['source']

setup.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,9 @@
1010
long_description=long_description,
1111
long_description_content_type='text/markdown',
1212
classifiers=[
13-
'Development Status :: 5 - Production/Stable',
14-
'Intended Audience :: Developers',
15-
'License :: OSI Approved :: MIT License',
16-
'Programming Language :: Python :: 3',
17-
'Programming Language :: Python :: 3.6',
18-
'Programming Language :: Python :: 3.7'
13+
'Development Status :: 5 - Production/Stable', 'Intended Audience :: Developers',
14+
'License :: OSI Approved :: MIT License', 'Programming Language :: Python :: 3',
15+
'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7'
1916
],
2017
keywords='codeforces',
2118
url='https://github.com/Mukundan314/python-codeforces',
@@ -25,13 +22,10 @@
2522
packages=find_packages(exclude=['docs']),
2623
install_requires=['beautifulsoup4', 'colorama', 'requests'],
2724
extras_requires={'docs': ['sphinx', 'sphinx_rtd_theme']},
28-
entry_points={
29-
'console_scripts': ['cf-run = codeforces.cf_run:main']
30-
},
25+
entry_points={'console_scripts': ['cf-run = codeforces.cf_run:main']},
3126
python_requires='>=3.6,<4',
3227
project_urls={
3328
"Bug Tracker": "https://github.com/Mukundan314/python-codeforces/issues/",
3429
"Documentation": "https://python-codeforces.readthedocs.io/en/stable/",
3530
"Source": "https://github.com/Mukundan314/python-codeforces"
36-
}
37-
)
31+
})

test/test_problem.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def test_normal_problem(self):
99

1010
title, time_limit, memory_limit, sample_tests = codeforces.problem.get_info(contest_id, index)
1111

12-
assert(title == 'A. Theatre Square')
13-
assert(time_limit == '1 second')
14-
assert(memory_limit == '256 megabytes')
15-
assert(list(sample_tests) == [('6 6 4', '4')])
12+
assert (title == 'A. Theatre Square')
13+
assert (time_limit == '1 second')
14+
assert (memory_limit == '256 megabytes')
15+
assert (list(sample_tests) == [('6 6 4', '4')])

0 commit comments

Comments
 (0)