Daniel Skýpala
2 years ago
2 changed files with 44 additions and 0 deletions
@ -1,4 +1,35 @@ |
|||||
|
from typing import List, Tuple, Optional |
||||
|
from datetime import datetime |
||||
|
import requests |
||||
|
import json |
||||
|
|
||||
KSP_URL = "https://ksp.mff.cuni.cz" |
KSP_URL = "https://ksp.mff.cuni.cz" |
||||
|
|
||||
def task_link(task_code: str, solution : bool = False): |
def task_link(task_code: str, solution : bool = False): |
||||
return f"{KSP_URL}/viz/{task_code}/{'reseni' if solution else ''}" |
return f"{KSP_URL}/viz/{task_code}/{'reseni' if solution else ''}" |
||||
|
|
||||
|
def catalog(year : Optional[int] = None, tasks : bool = False): |
||||
|
year_str = "" |
||||
|
if year is not None: |
||||
|
year_str = f"year={year}" |
||||
|
tasks_str = f"tasks={str(tasks).lower()}" |
||||
|
|
||||
|
page = requests.get(f"{KSP_URL}/api/tasks/catalog?{year_str}&{tasks_str}") |
||||
|
return json.loads(page.text) |
||||
|
|
||||
|
def active_deadlines() -> List[Tuple[str, datetime]]: |
||||
|
deadlines = [] |
||||
|
now = datetime.now().astimezone() |
||||
|
cat = catalog() |
||||
|
for series in cat: |
||||
|
series_deadlines = [series["deadline"]] |
||||
|
if "deadline2" in series: |
||||
|
series_deadlines.append(series["deadline2"]) |
||||
|
series_deadlines = list(map(datetime.fromisoformat, series_deadlines)) |
||||
|
|
||||
|
for series_deadline in series_deadlines: |
||||
|
if now < series_deadline: |
||||
|
deadlines.append((series["id"], series_deadline)) |
||||
|
break |
||||
|
|
||||
|
return deadlines |
||||
|
Loading…
Reference in new issue