-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
27721c5
commit 1c0e055
Showing
4 changed files
with
99 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,50 @@ | ||
from codeforces_api import CodeforcesApi | ||
from requests import get | ||
import requests | ||
|
||
cf_api = CodeforcesApi() | ||
|
||
|
||
def has_successful_submission(user_data, contest_id, problem_index): | ||
for submission in user_data["result"]: | ||
def getTwoProblems(username, rating): | ||
rounded_rating = round(rating / 100) * 100 | ||
higher_rating = rounded_rating + 200 | ||
|
||
submissions_url = ( | ||
f"https://codeforces.com/api/user.status?handle={username}&from=1&count=1000000" | ||
) | ||
response = requests.get(submissions_url) | ||
data = response.json() | ||
if data["status"] != "OK": | ||
return [] | ||
|
||
solved_problems = set() | ||
for submission in data["result"]: | ||
if submission["verdict"] == "OK": | ||
problem_id = ( | ||
submission["problem"]["contestId"], | ||
submission["problem"]["index"], | ||
) | ||
solved_problems.add(problem_id) | ||
|
||
problems_url = "https://codeforces.com/api/problemset.problems" | ||
response = requests.get(problems_url) | ||
data = response.json() | ||
if data["status"] != "OK": | ||
return [] | ||
|
||
selected_problems = [] | ||
for problem in data["result"]["problems"]: | ||
if "rating" not in problem: | ||
continue | ||
if ( | ||
submission["verdict"] == "OK" | ||
and submission["problem"]["contestId"] == contest_id | ||
and submission["problem"]["index"] == problem_index | ||
problem["rating"] == rounded_rating | ||
and (problem["contestId"], problem["index"]) not in solved_problems | ||
): | ||
return True | ||
|
||
return False | ||
|
||
|
||
def get_contest_standings(contest_id): | ||
request_url = f"https://codeforces.com/api/contest.standings?contestId={contest_id}" | ||
response = get(request_url) | ||
response = response.json() | ||
return response | ||
|
||
|
||
def getTwoProblems(username, rating): | ||
final_problems = [0, 0] | ||
|
||
url = f"https://codeforces.com/api/user.status?handle={username}" | ||
response = get(url) | ||
user_data = response.json() | ||
|
||
for contest in cf_api.contest_list(): | ||
standings = get_contest_standings(contest.id) | ||
if standings["status"] == "OK": | ||
for problem in standings["result"]["problems"]: | ||
if final_problems[0] != 0 and final_problems[1] != 0: | ||
return final_problems | ||
if "rating" in problem and not has_successful_submission( | ||
user_data, contest.id, problem["index"] | ||
): | ||
if final_problems[0] != 0 and problem["rating"] == rating: | ||
final_problems[0] = problem | ||
if final_problems[1] != 0 and problem["rating"] == rating + 200: | ||
final_problems[1] = problem | ||
|
||
return final_problems | ||
|
||
selected_problems.append(problem) | ||
if len(selected_problems) == 2: | ||
break | ||
elif ( | ||
problem["rating"] == higher_rating | ||
and (problem["contestId"], problem["index"]) not in solved_problems | ||
): | ||
selected_problems.append(problem) | ||
if len(selected_problems) == 2: | ||
break | ||
|
||
print(getTwoProblems("probablyarth", 800)) | ||
return selected_problems |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters