fetch-problems.py (495B)
1 import json 2 import urllib.request 3 4 URL = "https://codeforces.com/api/problemset.problems" 5 6 def fetch(): 7 req = urllib.request.Request(URL, headers={"User-Agent": "Mozilla/5.0"}) 8 with urllib.request.urlopen(req) as r: 9 data = json.load(r) 10 if data["status"] != "OK": 11 raise RuntimeError(data.get("comment", "Codeforces API error")) 12 13 ids = [f"{p['contestId']}{p['index']}" for p in data["result"]["problems"]] 14 return ids 15 16 for problem in fetch(): 17 print(problem)