-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_sem_id.py
32 lines (26 loc) · 1.03 KB
/
get_sem_id.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
import re
import aiohttp
from bs4 import BeautifulSoup
from constants.constants import vtop_semID_list_url
from utils.payloads import get_attendance_semID_list_payload
async def _get_sem_id(sess: aiohttp.ClientSession, username: str, csrf: str):
async with sess.post(
vtop_semID_list_url,
data=get_attendance_semID_list_payload(username, csrf),
) as req:
return re.search('<option value="(A.*)"', await req.text()).group(1)
async def _get_all_sem_ids(sess: aiohttp.ClientSession, username: str, csrf: str):
async with sess.post(
vtop_semID_list_url,
data=get_attendance_semID_list_payload(username, csrf),
) as req:
# sem as list
# return re.findall('<option value="(A.*)"', await req.text())
soup = BeautifulSoup(await req.text(), "lxml")
sem_ids = {}
sem_ids_soup = soup.findAll("option")
for elem in sem_ids_soup:
id = elem["value"]
if id != "":
sem_ids[id] = elem.text.strip()
return sem_ids