-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_exam_schedule.py
65 lines (54 loc) · 1.96 KB
/
get_exam_schedule.py
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import re
import aiohttp
import pandas as pd
from io import StringIO
from utils.payloads import get_examSchedule_payload
from constants.constants import vtop_doExamSchedule_url
async def _get_examSchedule_page(
sess: aiohttp.ClientSession, username: str, semID: str, csrf: str
) -> str:
async with sess.post(
vtop_doExamSchedule_url, data=get_examSchedule_payload(username, semID, csrf)
) as req:
return await req.text()
def _return_dash_if_not_str(value):
if isinstance(value, str):
return value
else:
return "-"
async def _parse_examSchedule(examSchedule_page: str):
try:
examSchedule_table = pd.read_html(StringIO(examSchedule_page))[0]
except ValueError:
return {}
examSchedule_data = {}
current_exam = ""
for index, row in examSchedule_table.iterrows():
if index == 0:
continue
if re.search("\D", row[0]):
current_exam = row[0]
examSchedule_data[current_exam] = {}
else:
examSchedule_data[current_exam][row[1]] = {
"name": row[2],
"type": row[3],
"classID": row[4],
"slot": row[5],
"date": _return_dash_if_not_str(row[6]),
"session": _return_dash_if_not_str(row[7]),
"reportingTime": _return_dash_if_not_str(row[8]),
"duration": _return_dash_if_not_str(row[9]),
"venue": row[10].split("-")[0],
"roomNo": row[10].split("-")[1],
"seatLocation": row[11],
"seatNo": row[12],
}
examSchedule_data.pop("S.No.")
return examSchedule_data
async def get_examSchedule_data(
sess: aiohttp.ClientSession, username: str, semID: str, csrf: str
) -> dict:
examSchedule_page = await _get_examSchedule_page(sess, username, semID, csrf)
examSchedule_data = await _parse_examSchedule(examSchedule_page)
return examSchedule_data