Bot pro KSP Discord
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

45 lines
1.4 KiB

import feedparser
from typing import List, Tuple, Optional
from datetime import datetime
import requests
import json
KSP_URL = "https://ksp.mff.cuni.cz"
def task_link(task_code: str, solution : bool = False):
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
async def ksp_feed() -> feedparser.util.FeedParserDict:
return feedparser.parse(f"{KSP_URL}/ksp.feed")
def strip_id(id_):
text = f"{KSP_URL}/"
if id_.startswith(text):
id_ = id_[len(text):]
return id_