Skip to content

Commit 2a5f8e8

Browse files
authored
Fixes and improvements (#364)
* Fixed incorrect tags when requested with\without rating after opposite request * Improved testing * Fixed some mistyping * Fixed variable name from anonimus to anonymous
1 parent c7c4a9f commit 2a5f8e8

12 files changed

+110
-85
lines changed

.github/dependabot.yml

-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ updates:
1212
allow:
1313
- dependency-type: direct
1414
- dependency-type: indirect
15-
ignore:
16-
- dependency-name: "idna"
1715
- package-ecosystem: "github-actions"
1816
directory: "/"
1917
schedule:

.github/workflows/codeql-analysis.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ jobs:
2424
- name: Checkout repository
2525
uses: actions/checkout@v3
2626
- name: Initialize CodeQL
27-
uses: github/codeql-action/init@v1
27+
uses: github/codeql-action/init@v2
2828
with:
2929
languages: ${{ matrix.language }}
3030
- name: Autobuild
31-
uses: github/codeql-action/autobuild@v1
31+
uses: github/codeql-action/autobuild@v2
3232
- name: Perform CodeQL Analysis
33-
uses: github/codeql-action/analyze@v1
33+
uses: github/codeql-action/analyze@v2

.github/workflows/publish.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
- develop
88
tags:
99
- "*"
10-
pull_request:
10+
pull_request_target:
1111
branches:
1212
- master
1313
- develop
@@ -23,11 +23,11 @@ jobs:
2323
steps:
2424
- uses: actions/checkout@v3
2525
- name: Set up Python ${{ matrix.python-version }}
26-
uses: actions/setup-python@v3
26+
uses: actions/setup-python@v4
2727
with:
2828
python-version: ${{ matrix.python-version }}
2929
- name: Cache pip
30-
uses: actions/cache@v2.1.7
30+
uses: actions/cache@v3
3131
with:
3232
path: ~/.cache/pip
3333
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
@@ -47,11 +47,11 @@ jobs:
4747
steps:
4848
- uses: actions/checkout@v3
4949
- name: Set up Python 3.9
50-
uses: actions/setup-python@v3
50+
uses: actions/setup-python@v4
5151
with:
5252
python-version: 3.9
5353
- name: Cache pip
54-
uses: actions/cache@v2.1.7
54+
uses: actions/cache@v3
5555
with:
5656
path: ~/.cache/pip
5757
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
@@ -65,7 +65,7 @@ jobs:
6565
run: |
6666
python setup.py sdist
6767
- name: Publish distribution 📦 to PyPI
68-
uses: pypa/[email protected].0
68+
uses: pypa/[email protected].1
6969
with:
7070
password: ${{ secrets.pypi_password }}
7171
release:

.github/workflows/wiki.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
steps:
1414
- uses: actions/checkout@v3
1515
- name: Install Python 3.8
16-
uses: actions/setup-python@v3
16+
uses: actions/setup-python@v4
1717
with:
1818
python-version: 3.8
1919
- name: Install dependencies

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
tests/*
1212
!tests/test_api.py
1313
!tests/test_api_auth.py
14+
!tests/test_parser.py
1415
!tests/conftest.py
1516

1617
!codeforces_api/

codeforces_api/api_request_maker.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class CodeforcesApiRequestMaker:
2929
_secret = None
3030
_rand = 0
3131
assigned_rand = False
32-
anonimus = False
32+
anonymous = False
3333

3434
def __init__(self, api_key=None, secret=None, random_number=1000000):
3535
"""
@@ -46,19 +46,19 @@ def __init__(self, api_key=None, secret=None, random_number=1000000):
4646
random_number,
4747
)
4848
if api_key is None and secret is None:
49-
self.anonimus = True
49+
self.anonymous = True
5050
else:
5151
self._api_key = api_key
5252
self._secret = secret
53-
self.anonimus = False
53+
self.anonymous = False
5454
self._rand = random_number
5555

5656
def generate_request(self, method_name, **fields):
5757
"""
5858
Generates request URL and data for API.
5959
"""
6060
request_url = "https://codeforces.com/api/" + str(method_name)
61-
if not self.anonimus:
61+
if not self.anonymous:
6262
# Renew Rand
6363
if not self.assigned_rand:
6464
self.renew_rand()

codeforces_api/api_requests.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def __init__(self, api_key=None, secret=None, random_number=1000000, method="POS
6767

6868
def blog_entry_comments(self, blog_entry_id):
6969
"""
70-
Get blogEntry.commnets for blog, blog_entry_id required.
70+
Get blogEntry.comments for blog, blog_entry_id required.
7171
7272
Returns parsed response from codeforces.com.
7373
"""
@@ -309,7 +309,7 @@ def user_friends(self, only_online=False):
309309
310310
Returns parsed response from codeforces.com.
311311
"""
312-
if self.anonimus:
312+
if self.anonymous:
313313
raise TypeError("Auth is required.")
314314
return self._make_request(
315315
"user.friends", **{"onlyOnline": str(only_online).lower()}

codeforces_api/parse_methods.py

+17-11
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def get_solution(self, contest_id, submit_id):
3737
3838
contest_id is the id of contest.
3939
40-
submit_id is the id of sumbission.
40+
submit_id is the id of submission.
4141
"""
4242
solutionPage = self.session.get(
4343
"https://codeforces.com/contest/"
@@ -55,14 +55,15 @@ def get_solution(self, contest_id, submit_id):
5555

5656
def get_tags(self, contest_id, index, include_rating=False):
5757
"""
58-
Get tags of the given problem.
58+
Get tags in lexicographical order of the given problem.
5959
6060
contest_id is the number of the contest.
6161
6262
index is the number of the problem, better to be a capital letter. Also could be an integer or lowercase letter.
6363
6464
include_rating is bool which indicates include or not task rating.
6565
"""
66+
# If we don't have tags we should get them.
6667
if self.problem_tags == dict():
6768
cf_api = CodeforcesApi()
6869
for problem in cf_api.problemset_problems()["problems"]:
@@ -71,20 +72,25 @@ def get_tags(self, contest_id, index, include_rating=False):
7172
self.problem_tags[str(problem.contest_id)][
7273
str(problem.index)
7374
] = problem.tags
74-
if include_rating:
75-
try:
76-
self.problem_tags[str(problem.problem_id)][
77-
str(problem.index)
78-
].append("*" + str(problem.rating))
79-
except KeyError:
80-
pass
75+
try:
76+
self.problem_tags[str(problem.contest_id)][
77+
str(problem.index)
78+
].append("*" + str(problem.rating))
79+
except KeyError:
80+
pass
81+
self.problem_tags[str(problem.contest_id)][str(problem.index)].sort()
8182
if isinstance(index, int):
8283
index = chr(ord("A") + index)
8384
elif isinstance(index, str):
8485
if index.isnumeric():
8586
index = chr(ord("A") + int(index))
8687
index = index.capitalize()
8788
try:
88-
return self.problem_tags[str(contest_id)][index]
89+
if include_rating:
90+
return self.problem_tags[str(contest_id)][index]
91+
return self.problem_tags[str(contest_id)][index][1:]
8992
except KeyError:
90-
return self.problem_tags[str(int(contest_id) - 1)][index]
93+
# If problem included in more than one division.
94+
if include_rating:
95+
return self.problem_tags[str(int(contest_id) - 1)][index]
96+
return self.problem_tags[str(int(contest_id) - 1)][index][1:]

codeforces_api/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "2.0.10"
1+
__version__ = "2.0.11"

requirements.txt

+34-29
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,52 @@
11
appdirs==1.4.4
2-
astroid==2.9.3
3-
atomicwrites==1.4.0
4-
attrs==21.4.0
5-
black==22.1.0
6-
bleach==4.1.0
7-
certifi==2021.10.8
8-
chardet==4.0.0
9-
charset-normalizer==2.0.12
10-
click==8.0.4
11-
colorama==0.4.4
12-
docutils==0.18.1
2+
astroid==2.12.9
3+
atomicwrites==1.4.1
4+
attrs==22.1.0
5+
black==22.8.0
6+
bleach==5.0.1
7+
certifi==2022.6.15
8+
chardet==5.0.0
9+
charset-normalizer==2.1.1
10+
click==8.1.3
11+
colorama==0.4.5
12+
commonmark==0.9.1
13+
dill==0.3.5.1
14+
docutils==0.19
1315
idna==2.10
14-
importlib-metadata==4.11.2
16+
importlib-metadata==4.12.0
1517
iniconfig==1.1.1
1618
isort==5.10.1
17-
keyring==23.3.0
19+
keyring==23.9.1
1820
lazy-object-proxy==1.7.1
1921
lxml==4.9.1
2022
mccabe==0.6.1
2123
mypy-extensions==0.4.3
2224
packaging==21.3
23-
pathspec==0.9.0
24-
pkginfo==1.8.2
25+
pathspec==0.10.1
26+
pkginfo==1.8.3
27+
platformdirs==2.5.2
2528
pluggy==1.0.0
2629
py==1.11.0
27-
Pygments==2.11.2
28-
pylint==2.12.2
29-
pyparsing==3.0.7
30-
pytest==7.0.1
30+
Pygments==2.13.0
31+
pylint==2.15.2
32+
pyparsing==3.0.9
33+
pytest==7.1.3
3134
pywin32-ctypes==0.2.0
32-
readme-renderer==33.0
33-
regex==2022.3.2
34-
requests==2.27.1
35+
readme-renderer==37.1
36+
regex==2022.8.17
37+
requests==2.28.1
3538
requests-toolbelt==0.9.1
3639
rfc3986==2.0.0
40+
rich==12.5.1
3741
six==1.16.0
3842
toml==0.10.2
3943
tomli==2.0.1
40-
tqdm==4.63.0
41-
twine==3.8.0
42-
typed-ast==1.5.2
43-
typing-extensions==4.1.1
44-
urllib3==1.26.8
44+
tomlkit==0.11.4
45+
tqdm==4.64.1
46+
twine==4.0.1
47+
typed-ast==1.5.4
48+
typing_extensions==4.3.0
49+
urllib3==1.26.12
4550
webencodings==0.5.1
46-
wrapt==1.13.3
47-
zipp==3.7.0
51+
wrapt==1.14.1
52+
zipp==3.8.1

tests/test_api.py

+20-26
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
from codeforces_api import CodeforcesApi
66

77

8-
def test_blog_entry_comments(api_key, api_secret):
9-
api = CodeforcesApi(api_key, api_secret)
8+
def test_blog_entry_comments():
9+
api = CodeforcesApi()
1010
comments = api.blog_entry_comments(74291)
1111
for comment in comments:
1212
if comment.id == 584151:
1313
assert comment.creation_time_seconds == 1582795345
1414

1515

16-
def test_blog_entry_view(api_key, api_secret):
17-
api = CodeforcesApi(api_key, api_secret)
16+
def test_blog_entry_view():
17+
api = CodeforcesApi()
1818
blog_entry = api.blog_entry_view(74291)
1919
assert blog_entry.author_handle == "VadVergasov"
2020
assert blog_entry.original_locale == "ru"
@@ -32,8 +32,8 @@ def test_blog_entry_view(api_key, api_secret):
3232
assert blog_entry.content is None
3333

3434

35-
def test_contest_hacks(api_key, api_secret):
36-
api = CodeforcesApi(api_key, api_secret)
35+
def test_contest_hacks():
36+
api = CodeforcesApi()
3737
hacks = api.contest_hacks(1311)
3838
for hack in hacks:
3939
if hack.id == 615666:
@@ -93,8 +93,8 @@ def test_contest_list():
9393
break
9494

9595

96-
def test_contest_rating_changes(api_key, api_secret):
97-
api = CodeforcesApi(api_key, api_secret)
96+
def test_contest_rating_changes():
97+
api = CodeforcesApi()
9898
changes = api.contest_rating_changes(1313)
9999
for change in changes:
100100
if change.handle == "VadVergasov":
@@ -107,8 +107,8 @@ def test_contest_rating_changes(api_key, api_secret):
107107
break
108108

109109

110-
def test_contest_standings(api_key, api_secret):
111-
api = CodeforcesApi(api_key, api_secret)
110+
def test_contest_standings():
111+
api = CodeforcesApi()
112112
standings = api.contest_standings(1313, handles=["VadVergasov"])
113113
assert standings["contest"].id == 1313
114114
assert standings["contest"].name == "Codeforces Round #622 (Div. 2)"
@@ -197,8 +197,8 @@ def test_contest_status():
197197
assert row.points is None
198198

199199

200-
def test_problemset_problems(api_key, api_secret):
201-
api = CodeforcesApi(api_key, api_secret)
200+
def test_problemset_problems():
201+
api = CodeforcesApi()
202202
problemset = api.problemset_problems()
203203
for problem in problemset["problems"]:
204204
if problem.name == "Single Push":
@@ -215,8 +215,8 @@ def test_problemset_problems(api_key, api_secret):
215215
assert isinstance(statistic.contest_id, int)
216216

217217

218-
def test_recent_status(api_key, api_secret):
219-
api = CodeforcesApi(api_key, api_secret)
218+
def test_recent_status():
219+
api = CodeforcesApi()
220220
status = api.problemset_recent_status(1)[0]
221221
assert isinstance(status.id, int)
222222
assert isinstance(status.creation_time_seconds, int)
@@ -233,8 +233,8 @@ def test_recent_status(api_key, api_secret):
233233
assert status.points is None or isinstance(status.points, float)
234234

235235

236-
def test_recent_actions(api_key, api_secret):
237-
api = CodeforcesApi(api_key, api_secret)
236+
def test_recent_actions():
237+
api = CodeforcesApi()
238238
action = api.recent_actions()[0]
239239
assert isinstance(action.time_seconds, int)
240240
if hasattr(action, "blog_entry"):
@@ -243,8 +243,8 @@ def test_recent_actions(api_key, api_secret):
243243
assert isinstance(action.comment, Comment)
244244

245245

246-
def test_user_blog_entries(api_key, api_secret):
247-
api = CodeforcesApi(api_key, api_secret)
246+
def test_user_blog_entries():
247+
api = CodeforcesApi()
248248
entries = api.user_blog_entries("VadVergasov")
249249
for entry in entries:
250250
if entry.id == 74291:
@@ -264,14 +264,8 @@ def test_user_blog_entries(api_key, api_secret):
264264
assert entry.content is None
265265

266266

267-
def test_user_friends(api_key, api_secret):
268-
api = CodeforcesApi(api_key, api_secret)
269-
friends = api.user_friends()
270-
assert "aropan" in friends or "gepardo" in friends
271-
272-
273-
def test_user_info(api_key, api_secret, check_user):
274-
api = CodeforcesApi(api_key, api_secret)
267+
def test_user_info(check_user):
268+
api = CodeforcesApi()
275269
info = api.user_info(["VadVergasov", "tourist"])
276270
for user in info:
277271
check_user(user)

0 commit comments

Comments
 (0)