|
50 | 50 | 3. Random
|
51 | 51 | 4. Random remain [Problems that submitted but not accepted yet]
|
52 | 52 | 5. Category
|
| 53 | +6. Contest |
53 | 54 | """
|
54 | 55 | __user_input_submit = """Please select the submit method [0-4, default: 0]:
|
55 | 56 | 0. Back
|
|
72 | 73 | b. last page
|
73 | 74 | n. next page
|
74 | 75 | """
|
| 76 | +__user_input_contest_type = """Please select the contest type [0-2, default: 0]: |
| 77 | +0. Back |
| 78 | +1. Weekly contest |
| 79 | +2. Biweekly contest |
| 80 | +""" |
| 81 | +__user_input_contest_id_num = """Enter the contest ID number (e.g. 1, 2, etc.): """ |
| 82 | + |
75 | 83 | __user_input_favorite_method = """Please select the favorite method [0-2, default: 0]:
|
76 | 84 | 0. Back
|
77 | 85 | 1. List problems in the favorite
|
|
85 | 93 |
|
86 | 94 | __allow_all = lambda x: True
|
87 | 95 | __allow_all_not_empty = lambda x: bool(x.strip())
|
| 96 | +__allow_number = lambda x: bool(re.match(r"^\d+$", x)) |
88 | 97 |
|
89 | 98 |
|
90 | 99 | def input_until_valid(prompt, check_func, error_msg=None):
|
@@ -283,6 +292,40 @@ def get_problem(languages, problem_folder, cookie):
|
283 | 292 | print(f"Problem [{problem_id}] fetched successfully.")
|
284 | 293 | else:
|
285 | 294 | print(f"Failed to fetch the problem. Check {problem_id} is correct?")
|
| 295 | + case "6": |
| 296 | + contest_type = input_until_valid( |
| 297 | + __user_input_contest_type, |
| 298 | + lambda x: x in ["0", "1", "2"], |
| 299 | + "Invalid input, please enter 1 for weekly contest, 2 for biweekly contest, or 0 to go back." |
| 300 | + ) |
| 301 | + print(__separate_line) |
| 302 | + contest_id = input_until_valid( |
| 303 | + __user_input_contest_id_num, |
| 304 | + __allow_number, |
| 305 | + "Invalid input, please enter a number." |
| 306 | + ) |
| 307 | + print(__separate_line) |
| 308 | + if contest_type == "0": |
| 309 | + return |
| 310 | + elif contest_type == "1": |
| 311 | + contest_id = f"weekly-contest-{contest_id}" |
| 312 | + elif contest_type == "2": |
| 313 | + contest_id = f"biweekly-contest-{contest_id}" |
| 314 | + else: |
| 315 | + print("Invalid contest type, please try again.") |
| 316 | + continue |
| 317 | + contest_questions = contest_lib.get_contest_info(contest_id) |
| 318 | + results = [] |
| 319 | + with ThreadPoolExecutor(max_workers=max(1, len(contest_questions))) as executor: |
| 320 | + for question_data in contest_questions: |
| 321 | + results.append( |
| 322 | + executor.submit(get_problem_main, problem_slug=question_data["title_slug"], force=True, |
| 323 | + cookie=cookie, skip_language=True, |
| 324 | + languages=languages, problem_folder=problem_folder)) |
| 325 | + for future in results: |
| 326 | + exit_code = future.result() |
| 327 | + if exit_code != 0: |
| 328 | + print("Failed to fetch a contest problem. Please check the contest ID and try again.") |
286 | 329 | case _:
|
287 | 330 | return
|
288 | 331 |
|
|
0 commit comments