online-judge-tools / api-client

API client to develop tools for competitive programming
MIT License
64 stars 18 forks source link

oj can't download tests from Codeforces Educational (EDU) #94

Closed aberent closed 4 years ago

aberent commented 4 years ago

Description

Codeforces have recently added an educational section (see https://codeforces.com/edu/courses) containing videos and associated practice problems. The problems have URLs such as https://codeforces.com/edu/course/2/lesson/2/1/practice/contest/269100/problem/A which oj doesn't recognise as valid problem URLs.

The source of this seems to be patterns used for Codeforces URLs in onlinejudge/service/codeforces.py.

Error log

oj -v download https://codeforces.com/edu/course/2/lesson/4/1/practice/contest/273169/problem/A
[DEBUG] load the cache for update checking: /home/anthony/.cache/online-judge-tools/pypi.json
[DEBUG] load the cache for update checking: /home/anthony/.cache/online-judge-tools/pypi.json
[DEBUG] args: Namespace(cookie=PosixPath('/home/anthony/.local/share/online-judge-tools/cookie.jar'), directory=None, dry_run=False, format=None, json=False, silent=False, subcommand='download', system=False, url='https://codeforces.com/edu/course/2/lesson/4/1/practice/contest/273169/problem/A', verbose=True, version=False, yukicoder_token=None)
[INFO] online-judge-tools 10.1.1 (+ online-judge-api-client 10.3.0)
[ERROR] unknown problem: https://codeforces.com/edu/course/2/lesson/4/1/practice/contest/273169/problem/A
[DEBUG] 
Traceback (most recent call last):
  File "/home/anthony/.local/lib/python3.8/site-packages/onlinejudge_command/main.py", line 242, in main
    run_program(parsed, parser=parser)
  File "/home/anthony/.local/lib/python3.8/site-packages/onlinejudge_command/main.py", line 208, in run_program
    download(args)
  File "/home/anthony/.local/lib/python3.8/site-packages/onlinejudge_command/subcommand/download.py", line 36, in download
    raise requests.exceptions.InvalidURL('The contest "%s" is not supported' % args.url)
requests.exceptions.InvalidURL: The contest "https://codeforces.com/edu/course/2/lesson/4/1/practice/contest/273169/problem/A" is not supported

[ERROR] The contest "https://codeforces.com/edu/course/2/lesson/4/1/practice/contest/273169/problem/A" is not supported
Traceback (most recent call last):
  File "/home/anthony/.local/lib/python3.8/site-packages/onlinejudge_command/main.py", line 242, in main
    run_program(parsed, parser=parser)
  File "/home/anthony/.local/lib/python3.8/site-packages/onlinejudge_command/main.py", line 208, in run_program
    download(args)
  File "/home/anthony/.local/lib/python3.8/site-packages/onlinejudge_command/subcommand/download.py", line 36, in download
    raise requests.exceptions.InvalidURL('The contest "%s" is not supported' % args.url)
requests.exceptions.InvalidURL: The contest "https://codeforces.com/edu/course/2/lesson/4/1/practice/contest/273169/problem/A" is not supported

Other notes

kmyk commented 4 years ago

Thank you for reporting! It seems we need to add a new URL pattern. URL https://codeforces.com/edu/contest/269100/problem/A is not redirected to URL https://codeforces.com/edu/course/2/lesson/2/1/practice/contest/269100/problem/A, so we cannot ignore /edu/... part.

Fixing seems easy. There is already another unusual URL pattern (GYM problems), so we need to just a new one for EDU.

aberent commented 4 years ago

Yes, not too bad. I am creating a pull request to fix it. Apart from adding a new pattern, the URLs generated from the contest ids are not valid. One can lesson from the problem URL, but one can't get it from the contest id, so doing this would require some refactoring. In my initial pull request I will simply disable context information for EDU problems (as is done for problemset problems).

Thank you for reporting! It seems we need to add a new URL pattern. URL https://codeforces.com/edu/contest/269100/problem/A is not redirected to URL https://codeforces.com/edu/course/2/lesson/2/1/practice/contest/269100/problem/A, so we cannot ignore /edu/... part.

Fixing seems easy. There is already another unusual URL pattern (GYM problems), so we need to just a new one for EDU.