complete dualis async
This commit is contained in:
102
fetchDUALIS.py
102
fetchDUALIS.py
@ -43,7 +43,7 @@ async def checkUser(email: str, password: str):
|
||||
return token, cookie
|
||||
|
||||
|
||||
def getKurs(token: int, cookie: str):
|
||||
async def getKurs(token: int, cookie: str):
|
||||
"""
|
||||
Bestimmt aus der ersten Prüfung den Kursbezeichner des Users.
|
||||
TODO: Umstellen auf Bezeichner INKL. Standort
|
||||
@ -54,34 +54,34 @@ def getKurs(token: int, cookie: str):
|
||||
try:
|
||||
headers["Cookie"] = "cnsc=" + cookie
|
||||
token = str(token)
|
||||
response = requests.request("GET", url +
|
||||
"?APPNAME=CampusNet&PRGNAME=COURSERESULTS&ARGUMENTS=-N" + token + ",-N000307,",
|
||||
headers=headers, data={})
|
||||
html = BeautifulSoup(response.text, 'lxml')
|
||||
link = html.body.find('a', attrs={'id': "Popup_details0001"})['href']
|
||||
response = requests.request("GET", url + link[21:], headers=headers, data={})
|
||||
html = BeautifulSoup(response.text, 'lxml')
|
||||
content = html.body.find('td', attrs={'class': 'level02'}).text
|
||||
start = content.find(" ") + 4
|
||||
end = start + (content[start:].find(" "))
|
||||
kurs = content[start:end]
|
||||
async with httpx.AsyncClient as s:
|
||||
response = await s.get(url=f"{url}?APPNAME=CampusNet&PRGNAME=COURSERESULTS&ARGUMENTS=-N{token},-N000307,",
|
||||
headers=headers)
|
||||
html = BeautifulSoup(response.text, 'lxml')
|
||||
link = html.body.find('a', attrs={'id': "Popup_details0001"})['href']
|
||||
response = requests.request("GET", url + link[21:], headers=headers, data={})
|
||||
html = BeautifulSoup(response.text, 'lxml')
|
||||
content = html.body.find('td', attrs={'class': 'level02'}).text
|
||||
start = content.find(" ") + 4
|
||||
end = start + (content[start:].find(" "))
|
||||
kurs = content[start:end]
|
||||
except AttributeError:
|
||||
kurs = 0
|
||||
return kurs
|
||||
|
||||
|
||||
def logOut(token: int, cookie: str):
|
||||
async def logOut(token: int, cookie: str):
|
||||
"""
|
||||
Invalidiert Token und Cookie bei Dualis.
|
||||
:param token:
|
||||
:param cookie:
|
||||
"""
|
||||
headers["Cookie"] = "cnsc=" + cookie
|
||||
requests.request("GET", url + "?APPNAME=CampusNet&PRGNAME=LOGOUT&ARGUMENTS=-N" + str(token)
|
||||
+ ", -N001", headers=headers, data={})
|
||||
async with httpx.AsyncClient() as s:
|
||||
await s.get(url=f"{url}?APPNAME=CampusNet&PRGNAME=LOGOUT&ARGUMENTS=-N{token}, -N001", headers=headers)
|
||||
|
||||
|
||||
def getSem(token: int, cookie: str):
|
||||
async def getSem(token: int, cookie: str):
|
||||
"""
|
||||
Liefert die Liste aller auf Dualis verfügbaren Semester.
|
||||
:param token:
|
||||
@ -90,21 +90,21 @@ def getSem(token: int, cookie: str):
|
||||
"""
|
||||
headers["Cookie"] = "cnsc=" + cookie
|
||||
token = str(token)
|
||||
response = requests.request("GET", url +
|
||||
"?APPNAME=CampusNet&PRGNAME=COURSERESULTS&ARGUMENTS=-N" + token + ",-N000307,",
|
||||
headers=headers, data={})
|
||||
html = BeautifulSoup(response.text, 'lxml')
|
||||
select = html.find('select')
|
||||
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']]]
|
||||
return optlist
|
||||
async with httpx.AsyncClient() as s:
|
||||
response = await s.get(url=f"{url}?APPNAME=CampusNet&PRGNAME=COURSERESULTS&ARGUMENTS=-N{token},-N000307,",
|
||||
headers=headers)
|
||||
html = BeautifulSoup(response.text, 'lxml')
|
||||
select = html.find('select')
|
||||
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']]]
|
||||
return optlist
|
||||
|
||||
|
||||
def getResults(token, cookie: str, resl: str):
|
||||
async def getResults(token, cookie: str, resl: str):
|
||||
"""
|
||||
Liefert die Liste aller Prüfungsergebnisse eines Semesters.
|
||||
:param token:
|
||||
@ -113,31 +113,43 @@ def getResults(token, cookie: str, resl: str):
|
||||
:return [[Name, Note, Credits], ...]:
|
||||
"""
|
||||
headers["Cookie"] = "cnsc=" + cookie
|
||||
response = requests.request("GET", url + "?APPNAME=CampusNet&PRGNAME=COURSERESULTS&ARGUMENTS=-N" + token +
|
||||
",-N000307," + ",-N" + resl, headers=headers, data={})
|
||||
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 = []
|
||||
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:
|
||||
col[2] = getPruefung(row.find("a")["href"])
|
||||
async with httpx.AsyncClient() as s:
|
||||
response = await s.get(
|
||||
url=f"{url}?APPNAME=CampusNet&PRGNAME=COURSERESULTS&ARGUMENTS=-N{token},-N000307,,-N{resl}",
|
||||
headers=headers)
|
||||
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 = []
|
||||
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:
|
||||
tasks += [getPruefung(s, row.find("a")["href"])]
|
||||
col[2] = i
|
||||
i += 1
|
||||
vorlist += [col[1:4]]
|
||||
return vorlist
|
||||
notlisted = await asyncio.gather(*tasks, return_exceptions=True)
|
||||
for i in vorlist:
|
||||
for e in range(0, len(i)):
|
||||
if isinstance(i[e], int):
|
||||
i[e] = notlisted[i[e]]
|
||||
return vorlist[:-1]
|
||||
|
||||
|
||||
def getPruefung(url):
|
||||
async def getPruefung(s, url):
|
||||
"""
|
||||
Ermittelt Noten "geschachtelter" Prüfungen, die nicht auf der Hauptseite angezeigt werden.
|
||||
TODO: Namen der spezifischen Prüfungen auch zurückgeben, um Zusammensetzung zu spezifizieren.
|
||||
:param s:
|
||||
:param url:
|
||||
:return list:
|
||||
"""
|
||||
response = requests.request("GET", "https://dualis.dhbw.de" + url, headers=headers, data={})
|
||||
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")
|
||||
|
||||
Reference in New Issue
Block a user