Skip to content

Commit abe84a3

Browse files
committed
add Prüfungsloop
non-working. L98 currently only returns one giant string instead of list of strings
1 parent ba76b55 commit abe84a3

File tree

1 file changed

+36
-7
lines changed

1 file changed

+36
-7
lines changed

campusnet.py

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@
4747

4848
## Get all Prüfungen in Semester
4949

50-
table=list() # table is cross semester, so initialized outside
50+
print("Getting Modules")
51+
52+
overview=list() # table is cross semester, so initialized outside
5153

5254
for semestername in semester:
5355
print(semestername)
@@ -56,9 +58,9 @@
5658
'Cookie': cnsc,
5759
}
5860
response = requests.get(f'https://dualis.dhbw.de/scripts/mgrqispi.dll?APPNAME=CampusNet&PRGNAME=COURSERESULTS&ARGUMENTS=-N518587923698845,-N000019,-N{semester[semestername]}', data="", headers=headers) #get page with Prüfungen Table
59-
temptable = re.findall('<table class="nb list">[\s\S]*</table>', response.text)[0] # extract table from html body
60-
temptable = re.findall('<tbody>[\s\S]*</tbody>', temptable)[0] # extract table body from table
61-
temprows = temptable.split('<tr')[1:-1] # extract all rows from table. [0] is just <tbody ...>
61+
tempoverview = re.findall('<table class="nb list">[\s\S]*</table>', response.text)[0] # extract table from html body
62+
tempoverview = re.findall('<tbody>[\s\S]*</tbody>', tempoverview)[0] # extract table body from table
63+
temprows = tempoverview.split('<tr')[1:-1] # extract all rows from table. [0] is just <tbody ...>
6264

6365
for row in temprows:
6466
tempcells = row.split('<td')[1:] # extract all columns from table
@@ -69,8 +71,35 @@
6971
cell = cell.split('href="', 1)[1].split('">')[0].replace("&amp;", "&") #only take content in a href="..." and convert url-encoding back to normal
7072
currentrow.append(cell) # combine cells to row
7173
currentrow = currentrow[:-1] # i know thats horrible coding, i dont know where that extra cell is from, please fix TODO
72-
table.append(currentrow) # combine rows to table
74+
overview.append(currentrow) # combine rows to table
75+
76+
print(overview)
77+
78+
## Get Prüfungen Results
7379

74-
print(table)
80+
print("Getting Prüfungsresults")
7581

76-
## Get Prüfungen Results
82+
detailview = list() # ['Modulenr', 'Name', 'Course', 'Semester', 'Prüfung', 'Date', 'Bewertung']
83+
84+
for module in overview:
85+
print(module[1])
86+
headers = {'Host': 'dualis.dhbw.de', 'Cookie': cnsc,}
87+
response = requests.get(f'https://dualis.dhbw.de{module[-1]}', data="", headers=headers)
88+
tempdetails = re.findall('<table class="tb"[\s\S]*</table>', response.text)[0] # extract first table from html body, as it contains the prüfungen
89+
while '<td class="level02"' in tempdetails:
90+
currentrow = list()
91+
currentrow.append(module[0])
92+
currentrow.append(module[1])
93+
tempdetails = tempdetails.split('<td class="level02"', 1)[1].split('>', 1)[1].split('</td',1) #remove everything before "level2"-heading. and split left of td end and right. left goes into table, right will be further edited.
94+
currentrow.append(tempdetails[0])
95+
tempdetails = tempdetails[1]
96+
if '<tr>' not in tempdetails: detailview.append(currentrow); break
97+
tempdetails = tempdetails.split('<tr>', 1)[1].split('</tr>',1) #cut off before next <tr> and split at /tr. [0] is not prüfungstable, [1] is for the next loop
98+
for cell in re.findall('<td .*>[\s\S]*</td>', tempdetails[0]): #loops over all td elements #TODO this only returns one giant match instead of a list of multiple matches???
99+
currentrow.append(tempdetails[0].split('>', 1)[1].split('<')[0]) #get content between html tags
100+
#currentrow = currentrow[] #last two are extern anerkannt and empty, so they get cut off
101+
102+
detailview.append(currentrow)
103+
tempdetails = tempdetails[1] #ready for the next loop
104+
105+
print(detailview)

0 commit comments

Comments
 (0)