Refactoring
This commit is contained in:
@ -25,10 +25,10 @@ async def checkUser(email: str, password: str):
|
||||
:return (Token, Cookie):
|
||||
"""
|
||||
async with httpx.AsyncClient() as s:
|
||||
fpw = urllib.parse.quote(password, safe='', encoding=None, errors=None)
|
||||
fmail = urllib.parse.quote(email, safe='', encoding=None, errors=None)
|
||||
content = (f'usrname={fmail}&pass={fpw}&ARGUMENTS=clino%2Cusrname%2Cpass%2Cmenuno%2Cmenu_type%2Cbrowser'
|
||||
f'%2Cplatform&APPNAME=CampusNet&PRGNAME=LOGINCHECK')
|
||||
formattedPassword = urllib.parse.quote(password, safe='', encoding=None, errors=None)
|
||||
formattedEmail = urllib.parse.quote(email, safe='', encoding=None, errors=None)
|
||||
content = (f"usrname={formattedEmail}&pass={formattedPassword}&ARGUMENTS=clino%2Cusrname%2Cpass%2C"
|
||||
f"menuno%2Cmenu_type%2Cbrowser%2Cplatform&APPNAME=CampusNet&PRGNAME=LOGINCHECK")
|
||||
response = await s.post(url=url, headers=headers, content=content)
|
||||
header = response.headers
|
||||
try:
|
||||
@ -48,7 +48,7 @@ async def getKurs(token: int, cookie: str):
|
||||
TODO: Umstellen auf Bezeichner INKL. Standort
|
||||
:param token:
|
||||
:param cookie:
|
||||
:return Kurs-Bezeichner:
|
||||
:return Kurs-Bezeichner ODER 0 bei Fehler:
|
||||
"""
|
||||
try:
|
||||
headers["Cookie"] = "cnsc=" + cookie
|
||||
@ -97,9 +97,9 @@ async def getSem(token: int, cookie: str):
|
||||
select = select.find_all(value=True)
|
||||
optlist = []
|
||||
for i in select:
|
||||
t = i.text.replace("Wi", "Winter").replace("So", "Sommer")
|
||||
t = t.replace("Se", "semester")
|
||||
optlist += [[t, i['value']]]
|
||||
text = i.text.replace("Wi", "Winter").replace("So", "Sommer")
|
||||
text = text.replace("Se", "semester")
|
||||
optlist += [[text, i['value']]]
|
||||
return optlist
|
||||
|
||||
|
||||
@ -119,25 +119,25 @@ async def getResults(token, cookie: str, resl: str):
|
||||
html = BeautifulSoup(response.content.decode("utf-8"), 'lxml')
|
||||
table = html.find('table', attrs={"class": "nb list"})
|
||||
body = table.find("tbody")
|
||||
vorl = body.find_all("tr")
|
||||
vorlist = []
|
||||
vorlesungen = body.find_all("tr")
|
||||
vorlesungenList = []
|
||||
tasks = []
|
||||
i = 0
|
||||
for row in vorl:
|
||||
cols = row.find_all("td")
|
||||
col = [[e.text.strip()] for e in cols]
|
||||
if len(col) != 0:
|
||||
if len(col[4][0]) == 0 or len(col[2][0]) == 0:
|
||||
for row in vorlesungen:
|
||||
columns = row.find_all("td")
|
||||
column = [[e.text.strip()] for e in columns]
|
||||
if len(column) != 0:
|
||||
if len(column[4][0]) == 0 or len(column[2][0]) == 0:
|
||||
tasks += [getPruefung(s, row.find("a")["href"])]
|
||||
col[2] = i
|
||||
column[2] = i
|
||||
i += 1
|
||||
vorlist += [col[1:4]]
|
||||
vorlesungenList += [column[1:4]]
|
||||
notlisted = await asyncio.gather(*tasks, return_exceptions=True)
|
||||
for i in vorlist:
|
||||
for i in vorlesungenList:
|
||||
for e in range(0, len(i)):
|
||||
if isinstance(i[e], int):
|
||||
i[e] = notlisted[i[e]]
|
||||
return vorlist[:-1]
|
||||
return vorlesungenList[:-1]
|
||||
|
||||
|
||||
async def getPruefung(s, url):
|
||||
@ -146,24 +146,24 @@ async def getPruefung(s, url):
|
||||
TODO: Namen der spezifischen Prüfungen auch zurückgeben, um Zusammensetzung zu spezifizieren.
|
||||
:param s:
|
||||
:param url:
|
||||
:return list:
|
||||
:return Noten-Liste:
|
||||
"""
|
||||
response = await s.get("https://dualis.dhbw.de" + url, headers=headers)
|
||||
html = BeautifulSoup(response.content.decode("utf-8"), 'lxml')
|
||||
table = html.find('table')
|
||||
pruefung = table.find_all("tr")
|
||||
ret = []
|
||||
returnList = []
|
||||
for row in pruefung:
|
||||
cols = row.find_all("td")
|
||||
col = [e.text.strip() for e in cols]
|
||||
if len(col) == 6 and len(col[3]) <= 13:
|
||||
if len(col[3]) != 0:
|
||||
ret += [col[0] + ": " + col[3].split("\xa0")[0]]
|
||||
if ret[-1][0] == ':':
|
||||
ret[-1] = "Gesamt" + ret[-1]
|
||||
if len(ret) == 0:
|
||||
ret = ["Noch nicht gesetzt"]
|
||||
return ret
|
||||
columns = row.find_all("td")
|
||||
column = [e.text.strip() for e in columns]
|
||||
if len(column) == 6 and len(column[3]) <= 13:
|
||||
if len(column[3]) != 0:
|
||||
returnList += [column[0] + ": " + column[3].split("\xa0")[0]]
|
||||
if returnList[-1][0] == ':':
|
||||
returnList[-1] = "Gesamt" + returnList[-1]
|
||||
if len(returnList) == 0:
|
||||
returnList = ["Noch nicht gesetzt"]
|
||||
return returnList
|
||||
|
||||
|
||||
def checkLifetime(timecode: float):
|
||||
|
||||
Reference in New Issue
Block a user