Skip to content

Commit

Permalink
Merge pull request #3 from TINF21CS1/dev
Browse files Browse the repository at this point in the history
working prototype v0.1
  • Loading branch information
JM-Lemmi authored Jul 1, 2022
2 parents 4535fe0 + 22b59b0 commit 0b225ac
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 15 deletions.
32 changes: 20 additions & 12 deletions CampusNet.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sys
from typing import Union
from typing import Union, List
from dataclasses import dataclass
import requests
from bs4 import BeautifulSoup
Expand All @@ -15,9 +15,10 @@ class Module:
name: str
credits: float
status: str
semester: str
semesters: List[str]
id: str
grade: Union[float, None] = None


@dataclass
class Exam:
Expand Down Expand Up @@ -159,15 +160,22 @@ def _get_modules(self):
# getting id for this module
exams_button = cells[5].find("a")
exams_id = exams_button.get("href").split(",-N")[-2]
modules.append(Module(
num=cells[0].text.strip(),
name=cells[1].text.strip(),
credits=float(cells[3].text.strip().replace(',', '.')),
status=cells[4].text.strip(),
semester=semester,
id=exams_id,
grade=grade
))
num = cells[0].text.strip()
if not any(module.num == num for module in modules):
modules.append(Module(
num=num,
name=cells[1].text.strip(),
credits=float(cells[3].text.strip().replace(',', '.')),
status=cells[4].text.strip(),
semesters=[semester],
id=exams_id,
grade=grade
))
else:
for module in modules:
if module.num == num:
module.semesters.append(semester)
break
elif len(cells) != 0:
# FIXME: proper logging
print("Unexpected number of cells:",
Expand Down Expand Up @@ -207,7 +215,7 @@ def get_exams_for_module(self, module: Module):
except ValueError:
grade = None
exams.append(Exam(
semester=module.semester,
semester=cells[0].text.strip(),
description=cells[1].text.strip(),
grade=grade,
))
Expand Down
6 changes: 3 additions & 3 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

```python
$ python3 -i CampusNet.py
>>> s = CampusNetSession("s######@student.dhbw-mannheim.de", "################")
>>> s = CampusNetSession("s211268@student.dhbw-mannheim.de", "sKviBuAYh9K3pyUdcbhyGMeJ3")
>>> s.modules
[Module(num='T3_1000', name='Praxisprojekt I', credits=20.0, status='', semester='SoSe 2022', id='381683598069776', grade=None), Module(num='T3INF1001', name='Mathematik I', credits=8.0, status='', semester='SoSe 2022', id='380685560144022', grade=None), Module(num='T3INF1002', name='Theoretische Informatik I (MA-TINF21CS1)', credits=5.0, status='', semester='SoSe 2022', id='382855008624547', grade=None), Module(num='T3INF1003', name='Theoretische Informatik II', credits=5.0, status='', semester='SoSe 2022', id='382214102615788', grade=None), Module(num='T3INF1004', name='Programmieren', credits=9.0, status='', semester='SoSe 2022', id='379974839816701', grade=None), Module(num='T3INF1005', name='Schlüsselqualifikationen', credits=5.0, status='', semester='SoSe 2022', id='379974840574866', grade=None), Module(num='T3INF4102', name='Einführung in die Kryptologie', credits=5.0, status='', semester='SoSe 2022', id='382214104541196', grade=None), Module(num='T3INF9000', name='Web and App Engineering', credits=5.0, status='', semester='SoSe 2022', id='379974842066225', grade=None), Module(num='T3INF1001', name='Mathematik I', credits=8.0, status='', semester='WiSe 2021/22', id='380685560144022', grade=None), Module(num='T3INF1006', name='Technische Informatik I', credits=5.0, status='bestanden', semester='WiSe 2021/22', id='380703425164844', grade=1.2), Module(num='T3INF9001', name='Cyber Security Basics', credits=3.0, status='bestanden', semester='WiSe 2021/22', id='379974841329087', grade=1.6)]
>>> s.get_exams_for_module(s.modules[10])
[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)]
>>> s.get_exams_for_module(s.modules[9])
[Exam(semester='WiSe 2021/22', description='Hausarbeit (100%)', grade=1.6)]
```
16 changes: 16 additions & 0 deletions print_exams_as_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import CampusNet
from tabulate import tabulate
from getpass import getpass

username = input("Username (mit @!): ")
password = getpass()

s = CampusNet.CampusNetSession(username, password)

table = list()

for module in s.modules:
for exam in s.get_exams_for_module(module):
table.append([module.num, module.name, exam.semester, exam.description, exam.grade])

print(tabulate(table))

0 comments on commit 0b225ac

Please sign in to comment.