fetch-data / scripts /codeforces_api.py
pjxcharya's picture
Update scripts/codeforces_api.py
93e79d1 verified
raw
history blame contribute delete
566 Bytes
import requests
import json
import os
def run_cf_sync():
# 1. Fetch data from Codeforces
c_resp = requests.get("https://codeforces.com/api/contest.list?gym=false")
contests = [c for c in c_resp.json()['result'] if c.get('phase') == "FINISHED"]
# 2. Logic to group/process (Simplified for example)
output_filename = "cf_contests.json"
with open(output_filename, "w") as f:
json.dump(contests[:50], f) # Limit for speed
# 3. Return the absolute path so Gradio can find the file
return os.path.abspath(output_filename)