Skip to content

Commit 94b80c4

Browse files
authored
Merge pull request #5 from TINF21CS1/dev
add Course Name
2 parents dde0a1c + e1e1be7 commit 94b80c4

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

CampusNet.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class Module:
2222

2323
@dataclass
2424
class Exam:
25+
name: Union[str, None]
2526
semester: str
2627
description: str
2728
grade: Union[float, None] = None
@@ -207,14 +208,18 @@ def get_exams_for_module(self, module: Module):
207208
soup = BeautifulSoup(response.text, 'html.parser')
208209
exam_table = soup.find('table', {'class': 'tb'})
209210
exams = []
211+
current_heading = None
210212
for row in exam_table.find_all("tr"):
211213
cells = row.find_all('td')
214+
if len(cells) == 1 and 'level02' in cells[0]["class"]:
215+
current_heading = cells[0].text.strip() #variable to persist header into the next iteration
212216
if len(cells) == 6 and all("tbdata" in cell["class"] for cell in cells):
213217
try:
214218
grade = float(cells[3].text.strip().replace(",", "."))
215219
except ValueError:
216220
grade = None
217221
exams.append(Exam(
222+
name=current_heading,
218223
semester=cells[0].text.strip(),
219224
description=cells[1].text.strip(),
220225
grade=grade,

Readme.md

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,47 @@
1-
## Example usage
1+
# CampusNet Python
2+
3+
## Usage Examples
4+
5+
### Exam Script
6+
7+
The `print_exams_as_table.py` script that is included in this repository will easily retrieve all Exams for a user and print them in a pretty table. This makes a quick overview very easy.
8+
9+
```
10+
PS > python .\print_exams_as_table.py
11+
Username (mit @!): [email protected]
12+
Password:
13+
--------- ---------------------------------------- ------------------------------------------------------ ------------ -------------------------------------------- ---
14+
T3_1000 Praxisprojekt I T3_1000.1 Projektarbeit 1 (MA-TINF21CS1) SoSe 2022 Projektarbeit (1%)
15+
T3_1000 Praxisprojekt I T3_1000.2 Wissenschaftliches Arbeiten 1 (MA-TINF21CS1) SoSe 2022 Ablauf- und Reflexionsbericht (1%)
16+
T3INF1001 Mathematik I T3INF1001.1 Lineare Algebra (MA-TINF21CS1) WiSe 2021/22 Klausurarbeit (50%) 2.9
17+
T3INF1001 Mathematik I T3INF1001.2 Analysis (MA-TINF21CS1) SoSe 2022 Klausurarbeit (50%) 3.1
18+
T3INF1002 Theoretische Informatik I (MA-TINF21CS1) Modulabschlussleistungen SoSe 2022 Klausurarbeit (100%)
19+
T3INF1003 Theoretische Informatik II Modulabschlussleistungen SoSe 2022 Klausurarbeit (100%)
20+
T3INF1004 Programmieren Modulabschlussleistungen SoSe 2022 Programmentwurf (100%)
21+
T3INF1005 Schlüsselqualifikationen Modulabschlussleistungen SoSe 2022 Klausurarbeit (< 50 %) (100%)
22+
T3INF4102 Einführung in die Kryptologie Modulabschlussleistungen SoSe 2022 Klausur 75 % und Laborarbeit 25 % (100%)
23+
T3INF9000 Web and App Engineering Modulabschlussleistungen SoSe 2022 Klausur 50 % und Programmentwurf 50 % (100%)
24+
T3INF1006 Technische Informatik I Modulabschlussleistungen WiSe 2021/22 Klausurarbeit (100%) 4
25+
T3INF9001 Cyber Security Basics Modulabschlussleistungen WiSe 2021/22 Hausarbeit (100%) 2.1
26+
--------- ---------------------------------------- ------------------------------------------------------ ------------ -------------------------------------------- ---
27+
```
28+
29+
### Python Package
30+
31+
You can also use CampusNet.py as an imported Package to interact in detail with CampusNet.
232

333
```python
4-
$ python3 -i CampusNet.py
34+
$ python
35+
>>> from CampusNet import *
536
>>> s = CampusNetSession("s***REMOVED***@student.dhbw-mannheim.de", "***REMOVED***")
637
>>> s.modules
738
[Module(num='T3_1000', name='Praxisprojekt I', credits=20.0, status='', semesters=['SoSe 2022'], id='381683598069776', grade=None), Module(num='T3INF1001', name='Mathematik I', credits=8.0, status='', semesters=['SoSe 2022', 'WiSe 2021/22'], id='380685560144022', grade=None), Module(num='T3INF1002', name='Theoretische Informatik I (MA-TINF21CS1)', credits=5.0, status='', semesters=['SoSe 2022'], id='382855008624547', grade=None), Module(num='T3INF1003', name='Theoretische Informatik II', credits=5.0, status='', semesters=['SoSe 2022'], id='382214102615788', grade=None), Module(num='T3INF1004', name='Programmieren', credits=9.0, status='', semesters=['SoSe 2022'], id='379974839816701', grade=None), Module(num='T3INF1005', name='Schlüsselqualifikationen', credits=5.0, status='', semesters=['SoSe 2022'], id='379974840574866', grade=None), Module(num='T3INF4102', name='Einführung in die Kryptologie', credits=5.0, status='', semesters=['SoSe 2022'], id='382214104541196', grade=None), Module(num='T3INF9000', name='Web and App Engineering', credits=5.0, status='', semesters=['SoSe 2022'], id='379974842066225', grade=None), Module(num='T3INF1006', name='Technische Informatik I', credits=5.0, status='bestanden', semesters=['WiSe 2021/22'], id='380703425164844', grade=1.2), Module(num='T3INF9001', name='Cyber Security Basics', credits=3.0, status='bestanden', semesters=['WiSe 2021/22'], id='379974841329087', grade=1.6)]
839
>>> s.get_exams_for_module(s.modules[9])
940
[Exam(semester='WiSe 2021/22', description='Hausarbeit (100%)', grade=1.6)]
1041
```
42+
43+
## Contribution
44+
45+
This package is still work in progress. If you need data from CampusNet, that is currently not retrieved by it, please feel free to open an Issue or even PR for it.
46+
47+
We are studying at DHBW Mannheim, so this package is tested with [https://dualis.dhbw.de](https://dualis.dhbw.de). But it should also be compatible with other CampusNet instances from other universities.

print_exams_as_table.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111

1212
for module in s.modules:
1313
for exam in s.get_exams_for_module(module):
14-
table.append([module.num, module.name, exam.semester, exam.description, exam.grade])
14+
table.append([module.num, module.name, exam.name, exam.semester, exam.description, exam.grade])
1515

1616
print(tabulate(table))

0 commit comments

Comments
 (0)