-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodechef.py
More file actions
47 lines (37 loc) · 1.3 KB
/
codechef.py
File metadata and controls
47 lines (37 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import pytz
import httpx
import asyncio
from datetime import datetime
try:
from helpers.format_time import secondsToTime, timeToSeconds
except ImportError:
from .helpers.format_time import secondsToTime, timeToSeconds
async def getContests(ses: httpx.AsyncClient):
r = (await ses.get('https://www.codechef.com/api/list/contests/all')).json()
if r.get("status") != "success":
return []
allContests = []
contests = r["future_contests"]
for i in contests:
name = i["contest_name"]
url = f"https://www.codechef.com/{i['contest_code']}"
startIso = i["contest_start_date_iso"]
startTime = datetime.fromisoformat(startIso).astimezone(
pytz.utc).strftime("%d-%m-%Y %H:%M:%S UTC")
durationMin = i["contest_duration"] + " minutes"
durationSec = timeToSeconds(durationMin)
duration = secondsToTime(durationSec)
contest = {
"name": name,
"url": url,
"startTime": startTime,
"duration": duration,
"durationSeconds": durationSec
}
allContests.append(contest)
return allContests
if __name__ == "__main__":
print("Only running one file.\n")
a = asyncio.run(getContests(httpx.AsyncClient(timeout=13)))
for j in a:
print(j)