pjxcharya commited on
Commit
93e79d1
·
verified ·
1 Parent(s): 390a186

Update scripts/codeforces_api.py

Browse files
Files changed (1) hide show
  1. scripts/codeforces_api.py +8 -13
scripts/codeforces_api.py CHANGED
@@ -3,19 +3,14 @@ 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
 
3
  import os
4
 
5
  def run_cf_sync():
6
+ # 1. Fetch data from Codeforces
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.get('phase') == "FINISHED"]
9
 
10
+ # 2. Logic to group/process (Simplified for example)
11
+ output_filename = "cf_contests.json"
12
+ with open(output_filename, "w") as f:
13
+ json.dump(contests[:50], f) # Limit for speed
14
 
15
+ # 3. Return the absolute path so Gradio can find the file
16
+ return os.path.abspath(output_filename)