scraping

Scripts for scraping sites
git clone git://git.laack.co/scraping.git
Log | Files | Refs

commit a66331054a3c5b89036343f04b1cccde4e0f73f1
parent 4d1b5ec1df70334ccdfc01c2cdd432b8d46a318d
Author: Andrew Laack <andrew@laack.co>
Date:   Sun,  8 Nov 2026 23:18:31 -0600

Refactor

Diffstat:
Mcodeforces/fetch-problems.py | 14++++----------
1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/codeforces/fetch-problems.py b/codeforces/fetch-problems.py @@ -2,10 +2,8 @@ import json import urllib.request URL = "https://codeforces.com/api/problemset.problems" -LIMIT = None - -def fetch(limit=LIMIT): +def fetch(): req = urllib.request.Request(URL, headers={"User-Agent": "Mozilla/5.0"}) with urllib.request.urlopen(req) as r: data = json.load(r) @@ -13,11 +11,7 @@ def fetch(limit=LIMIT): raise RuntimeError(data.get("comment", "Codeforces API error")) ids = [f"{p['contestId']}{p['index']}" for p in data["result"]["problems"]] - return ids[:limit] if limit else ids - + return ids -if __name__ == "__main__": - for problem in fetch(): - print(problem) -else: - PROBLEMS = fetch() +for problem in fetch(): + print(problem)