Last active
June 20, 2024 09:08
-
-
Save Apocryphon-X/4e87279d1c4060e4aa8549a988d63b8b to your computer and use it in GitHub Desktop.
Small script to compare two omegaUp profiles (This tool shows you what problems user B doesn't have that user A does).
This file contains hidden or 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
# MIT License: 2023 - Present | |
import requests | |
import os | |
import sys | |
import json | |
from rich import print | |
API_TOKEN = os.getenv("OMEGAUP_API_TOKEN") | |
ENTRYPOINT = "https://omegaup.com/api" | |
client = requests.Session() | |
client.headers["Authorization"] = f"token {API_TOKEN}" | |
class Problem: | |
def __init__(self, data_dict): | |
self.title = data_dict.get("title") | |
self.alias = data_dict.get("alias") | |
self.submissions = data_dict.get("submissions") | |
self.accepted = data_dict.get("accepted") | |
self.quality_seal = data_dict.get("quality_seal") | |
def __hash__(self): | |
return hash((self.title, self.alias)) | |
def __le__(self, other): | |
return self.submissions < self.submissions | |
def __eq__(self, other): | |
return self.alias == other.alias | |
def __neq__(self, other): | |
return not (self == other) | |
def __repr__(self): | |
return ( | |
f"Problem(alias='{self.alias}', submissions={self.submissions})\n" | |
f" ↪ https://omegaup.com/arena/problem/{self.alias}/" | |
) | |
def get_problems_from(target_username): | |
api_response = client.get( | |
url=f"{ENTRYPOINT}/user/problemsSolved", | |
params={"username": target_username} | |
) | |
return set( | |
Problem(x) for x in api_response.json()["problems"] | |
) | |
def get_created_problems_from(target_username): | |
api_response = client.get( | |
url=f"{ENTRYPOINT}/user/problemsCreated/", | |
params={"username": target_username} | |
) | |
return set( | |
Problem(x) for x in api_response.json()["problems"] | |
) | |
if len(sys.argv) <= 2: | |
print("[red]ERROR:[/red] Two usernames must be provided!") | |
exit(1) | |
user_a_problems = get_problems_from(sys.argv[1])#) | |
user_b_problems = get_problems_from(sys.argv[2])#) | |
user_a_problems = user_a_problems | get_created_problems_from(sys.argv[1]) | |
user_b_problems = user_b_problems | get_created_problems_from(sys.argv[2]) | |
requested_results = user_a_problems - user_b_problems | |
for problem in requested_results: | |
print(problem) | |
print("—" * 30) | |
sys.argv[1] += " " * max(0, 10 - len(sys.argv[1])) | |
sys.argv[2] += " " * max(0, 10 - len(sys.argv[2])) | |
print(f"{sys.argv[1]}\t {len(user_a_problems)}") | |
print(f"{sys.argv[2]}\t {len(user_b_problems)}") | |
print("—" * 30) | |
print(f"Δ = {len(requested_results)}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment