Spaces:
Runtime error
Runtime error
Update scripts/codeforces_api.py
Browse files- scripts/codeforces_api.py +21 -0
scripts/codeforces_api.py
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
import json
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
def run_cf_sync():
|
| 6 |
+
# Fetch contests
|
| 7 |
+
c_resp = requests.get("https://codeforces.com/api/contest.list?gym=false")
|
| 8 |
+
contests = [c for c in c_resp.json()['result'] if c['phase'] == "FINISHED"]
|
| 9 |
+
|
| 10 |
+
# Fetch problems
|
| 11 |
+
p_resp = requests.get("https://codeforces.com/api/problemset.problems")
|
| 12 |
+
all_problems = p_resp.json()['result']['problems']
|
| 13 |
+
|
| 14 |
+
# Simple Join Logic
|
| 15 |
+
data = {"contests": contests[:10], "problems": all_problems[:50]} # Example slice
|
| 16 |
+
|
| 17 |
+
output_path = "cf_data.json"
|
| 18 |
+
with open(output_path, "w") as f:
|
| 19 |
+
json.dump(data, f)
|
| 20 |
+
|
| 21 |
+
return output_path # Crucial for Gradio to find the file
|