53 lines
1.9 KiB
Python
53 lines
1.9 KiB
Python
import requests
|
|
import urllib.parse
|
|
import time
|
|
from bs4 import BeautifulSoup
|
|
|
|
headers = {
|
|
'Cookie': 'cnsc=0',
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'
|
|
}
|
|
|
|
url = "https://dualis.dhbw.de/scripts/mgrqispi.dll"
|
|
|
|
|
|
def checkUser(email: str, password: str):
|
|
s = requests.Session()
|
|
fpw = urllib.parse.quote(password, safe='', encoding=None, errors=None)
|
|
fmail = urllib.parse.quote(email, safe='', encoding=None, errors=None)
|
|
payload = 'usrname=' + fmail + '&pass=' + fpw + '&ARGUMENTS=clino%2Cusrname%2Cpass%2Cmenuno%2Cmenu_type%2Cbrowser%2Cplatform&APPNAME=CampusNet&PRGNAME=LOGINCHECK'
|
|
response = s.post(url, headers=headers, data=payload)
|
|
header = response.headers
|
|
try:
|
|
refresh = header["REFRESH"]
|
|
arg = refresh.find("=-N") + 3
|
|
komma = refresh[arg:].find(",")
|
|
except KeyError:
|
|
return -2, s
|
|
token = refresh[arg:komma + arg]
|
|
return token, s
|
|
|
|
|
|
def getKurs(token: str, cookie: int):
|
|
headers["Cookie"] = "cnsc=" + str(cookie)
|
|
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]
|
|
return kurs
|
|
|
|
|
|
def checkLifetime(timecode):
|
|
if time.time() - timecode > 1800:
|
|
return False
|
|
else:
|
|
return True
|