Spaces:
Paused
Paused
File size: 1,600 Bytes
5161c7a |
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 |
import aiohttp
import pandas as pd
from io import StringIO
from constants.constants import vtop_doMarks_view_url
from utils.payloads import get_doMarks_view_payload
async def _get_doMarks_view_page(
sess: aiohttp.ClientSession, username: str, semID: str, csrf: str
) -> str:
async with sess.post(
vtop_doMarks_view_url, data=get_doMarks_view_payload(username, semID, csrf)
) as req:
return await req.text()
def _parse_marks(marks_page):
try:
tables = pd.read_html(StringIO(marks_page))
except ValueError:
return {}
course_details = tables[0].iloc[1::2, :]
marks_data = {}
for i in range(course_details.shape[0]):
course = course_details.iloc[i]
marks_data[course[1]] = {
"courseName": course[3],
"courseType": course[4],
"professor": course[6],
"courseSlot": course[7],
"marks": {},
}
current_course_table = tables[i + 1]
for j in range(1, current_course_table.shape[0]):
entry = current_course_table.iloc[j]
marks_data[course[1]]["marks"][entry[1]] = {
"maxMarks": entry[2],
"maxWeightageMarks": entry[3],
"scoredMarks": entry[5],
"scoredWeightageMarks": entry[6],
}
return marks_data
async def get_marks_data(
sess: aiohttp.ClientSession, username: str, semID: str, csrf: str
):
return _parse_marks(await _get_doMarks_view_page(sess, username, semID, csrf))
|