Skip to content

Commit

Permalink
Update contest URLs and add duration property
Browse files Browse the repository at this point in the history
  • Loading branch information
rtk-rnjn committed Mar 29, 2024
1 parent 17e8366 commit 5f4b23d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
6 changes: 5 additions & 1 deletion cogs/rtfm/_kontests/codechef.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@ def name(self) -> str:

@property
def start_time(self) -> datetime.datetime:
return datetime.datetime.strptime(self.__data["start"], TIME_FORMAT)
return datetime.datetime.strptime(self.__data["start_in"], TIME_FORMAT)

@property
def url(self) -> str:
return f"{API}/{self.code}"

@property
def duration(self) -> str:
return self.__data["duration"]


class CodeChef:
def __init__(self) -> None:
Expand Down
8 changes: 4 additions & 4 deletions cogs/rtfm/_kontests/csacademy.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ class CSAcademyContestData:
def __init__(self, data: dict) -> None:
self.__data = data

@property
def id(self) -> int:
return self.__data["id"]

@property
def name(self) -> str:
return self.__data["longName"]
Expand Down Expand Up @@ -60,6 +56,10 @@ def description(self) -> str:
def rated(self) -> bool:
return self.__data["rated"]

@property
def url(self) -> str:
return f"{BASE_URL}/{self.__data['name']}"


class CSAcademy:
def __init__(self) -> None:
Expand Down
20 changes: 19 additions & 1 deletion cogs/rtfm/rtfm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1477,7 +1477,7 @@ async def kontest_codeforces(self) -> list:
contests = self.kontests_cache["codeforces"]

return [
f"""ID: *{contest.id}* | **[{contest.name}]({contest.website_url})** | {contest.phase} | {contest.difficulty}
f"""ID: *{contest.id}* | **[{contest.name}]({contest.website_url})** | {contest.phase}
{contest.description}
`Start:` {discord.utils.format_dt(contest.start_time, "R") if contest.start_time else 'TBA'}
`Time :` {contest.duration_seconds // 60} Minutes
Expand All @@ -1489,6 +1489,7 @@ async def kontest_atcoder(self) -> list:
if "atcoder" not in self.kontests_cache:
atcoder = AtCoder()
await atcoder.fetch(self.bot.http_session)
await atcoder.get_contests(self.bot.http_session)
self.kontests_cache["atcoder"] = atcoder.contests

contests = self.kontests_cache["atcoder"]
Expand All @@ -1497,6 +1498,23 @@ async def kontest_atcoder(self) -> list:
f"""ID: NA | **[{contest.name}]({contest.url})**
*Description not available*
`Start:` {discord.utils.format_dt(contest.start_time, "R")}
"""
for contest in contests
]

async def kontest_csacademy(self) -> list:
if "csacademy" not in self.kontests_cache:
csacademy = CSAcademy()
await csacademy.fetch(self.bot.http_session)
self.kontests_cache["csacademy"] = csacademy.contests

contests = self.kontests_cache["csacademy"]

return [
f"""ID: NA | **[{contest.name}]({contest.url})**
{contest.description}
`Start:` {discord.utils.format_dt(contest.start_time, "R") if contest.start_time else 'TBA'}
`End :` {discord.utils.format_dt(contest.end_time, "R") if contest.end_time else 'TBA'}
"""
for contest in contests
]

0 comments on commit 5f4b23d

Please sign in to comment.