Spaces:
Paused
Paused
File size: 2,012 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 |
import aiohttp
from constants.constants import user_agent_header
from utils.captcha_solver import solve_base64
from utils.payloads import get_login_payload
import re
async def gen_session(sess: aiohttp.ClientSession, username: str, password: str):
try:
async with sess.get(
"https://vtop.vitap.ac.in/vtop/", headers=user_agent_header
):
async with sess.get("https://vtop.vitap.ac.in/vtop/open/page") as csrf:
csrf_token = re.search(
r'name="_csrf" value="(.*)"', await csrf.text()
).group(1)
await sess.post(
"https://vtop.vitap.ac.in/vtop/prelogin/setup",
data={"_csrf": csrf_token, "flag": "VTOP"},
)
await sess.get("https://vtop.vitap.ac.in/vtop/init/page")
async with sess.get("https://vtop.vitap.ac.in/vtop/login") as req:
captcha = solve_base64(
re.search(r';base64,(.+)"', await req.text()).group(1)
)
async with sess.post(
"https://vtop.vitap.ac.in/vtop/login",
data=get_login_payload(
csrf_token,
username,
password,
captcha,
),
) as final:
csrf = re.search(
r'var csrfValue = "(.*)";', await final.text()
).group(1)
if "Invalid" in await final.text():
return 0
elif len(csrf) == 36:
return csrf
else:
return await gen_session(sess, username, password)
except Exception:
return await gen_session(sess, username, password)
|