Skip to content

Commit 44f0181

Browse files
committed
Move util script into module main
1 parent 49a51ae commit 44f0181

File tree

5 files changed

+92
-28
lines changed

5 files changed

+92
-28
lines changed

Readme.md

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,51 @@ pip install git+https://github.com/TINF21CS1/python-campusnet@dev
88

99
## Usage Examples
1010

11-
### Exam Script
11+
### Getting all exams and grades
1212

13-
The [`print_exams_as_table.py`](utils/print_exams_as_table.py) in `utils` 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.
13+
The module can be used directly to get information about all exams
1414

1515
```
16-
$ python print_exams_as_table.py
17-
Username (mit @!): [email protected]
16+
$ python -m campusnet -h
17+
usage: python -m campusnet [-h] [-b BASE_URL] [-o {table,json,csv}] username [password]
18+
19+
Get exams from CampusNet instance.
20+
21+
positional arguments:
22+
username Username (including domain)
23+
password Password (will be read from stdin if not supplied)
24+
25+
optional arguments:
26+
-h, --help show this help message and exit
27+
-b BASE_URL, --base-url BASE_URL
28+
Base URL of the CampusNet instance (default: https://dualis.dhbw.de/)
29+
-o {table,json,csv}, --output {table,json,csv}
30+
Output format of the data (default: table)
31+
```
32+
33+
```
34+
$ python -m campusnet s*******@student.dhbw-mannheim.de -b https://dualis.dhbw.de
1835
Password:
19-
--------- ---------------------------------------- ------------------------------------------------------ ------------ -------------------------------------------- ---
36+
Module Name Exam Semester Description Grade
37+
--------- ---------------------------------------- ------------------------------------------------------ ------------ -------------------------------------------- -------
2038
T3_1000 Praxisprojekt I T3_1000.1 Projektarbeit 1 (MA-TINF21CS1) SoSe 2022 Projektarbeit (1%)
2139
T3_1000 Praxisprojekt I T3_1000.2 Wissenschaftliches Arbeiten 1 (MA-TINF21CS1) SoSe 2022 Ablauf- und Reflexionsbericht (1%)
22-
T3INF1001 Mathematik I T3INF1001.1 Lineare Algebra (MA-TINF21CS1) WiSe 2021/22 Klausurarbeit (50%) 2.9
23-
T3INF1001 Mathematik I T3INF1001.2 Analysis (MA-TINF21CS1) SoSe 2022 Klausurarbeit (50%) 3.1
40+
T3INF1001 Mathematik I T3INF1001.1 Lineare Algebra (MA-TINF21CS1) WiSe 2021/22 Klausurarbeit (50%) *.*
41+
T3INF1001 Mathematik I T3INF1001.2 Analysis (MA-TINF21CS1) SoSe 2022 Klausurarbeit (50%) *.*
2442
T3INF1002 Theoretische Informatik I (MA-TINF21CS1) Modulabschlussleistungen SoSe 2022 Klausurarbeit (100%)
2543
T3INF1003 Theoretische Informatik II Modulabschlussleistungen SoSe 2022 Klausurarbeit (100%)
2644
T3INF1004 Programmieren Modulabschlussleistungen SoSe 2022 Programmentwurf (100%)
2745
T3INF1005 Schlüsselqualifikationen Modulabschlussleistungen SoSe 2022 Klausurarbeit (< 50 %) (100%)
2846
T3INF4102 Einführung in die Kryptologie Modulabschlussleistungen SoSe 2022 Klausur 75 % und Laborarbeit 25 % (100%)
2947
T3INF9000 Web and App Engineering Modulabschlussleistungen SoSe 2022 Klausur 50 % und Programmentwurf 50 % (100%)
30-
T3INF1006 Technische Informatik I Modulabschlussleistungen WiSe 2021/22 Klausurarbeit (100%) 4
31-
T3INF9001 Cyber Security Basics Modulabschlussleistungen WiSe 2021/22 Hausarbeit (100%) 2.1
32-
--------- ---------------------------------------- ------------------------------------------------------ ------------ -------------------------------------------- ---
48+
T3INF1006 Technische Informatik I Modulabschlussleistungen WiSe 2021/22 Klausurarbeit (100%) *.*
49+
T3INF9001 Cyber Security Basics Modulabschlussleistungen WiSe 2021/22 Hausarbeit (100%) *.*
50+
```--------------------------------------- ---
3351
```
3452

3553
### Python Package
3654

37-
You can also use CampusNet.py as an imported Package to interact in detail with CampusNet.
55+
You can also use `campusnet` as a package to interact with CampusNet from Python.
3856

3957
```python
4058
$ python
@@ -50,4 +68,4 @@ $ python
5068

5169
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.
5270

53-
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.
71+
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. If you have acess to another CampusNet instance and use our script, let us know how it goes :).

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
beautifulsoup4==4.11.*
22
requests==2.28.*
3+
tabulate==0.8.*

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ packages =
1919
install_requires =
2020
requests>=2
2121
beautifulsoup4>=4
22+
tabulate>=0.8
2223
python_requires = >=3.7
2324
package_dir =
2425
=src

src/campusnet/__main__.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import campusnet
2+
from argparse import ArgumentParser
3+
4+
if __name__ == "__main__":
5+
parser = ArgumentParser(prog="python -m campusnet",
6+
description="Get exams from CampusNet instance.")
7+
parser.add_argument("username", help="Username (including domain)")
8+
parser.add_argument(
9+
"password", help="Password (will be read from stdin if not supplied)", nargs="?", default=None)
10+
parser.add_argument(
11+
"-b", "--base-url", help="Base URL of the CampusNet instance (default: https://dualis.dhbw.de/)", default="https://dualis.dhbw.de/")
12+
parser.add_argument("-o", "--output", help="Output format of the data (default: table)",
13+
default="table", choices=["table", "json", "csv"])
14+
15+
args = parser.parse_args()
16+
if not args.password:
17+
from getpass import getpass
18+
password = getpass()
19+
else:
20+
password = args.password
21+
22+
while True:
23+
try:
24+
s = campusnet.CampusNetSession(args.username, password)
25+
break
26+
except campusnet.LoginError as e:
27+
print("Invalid username or password.")
28+
if not args["password"]:
29+
password = getpass()
30+
else:
31+
exit(1)
32+
33+
if args.output == "table":
34+
from tabulate import tabulate
35+
table = []
36+
for module in s.modules:
37+
for exam in s.get_exams_for_module(module):
38+
table.append([module.num, module.name, exam.name,
39+
exam.semester, exam.description, exam.grade])
40+
41+
print(tabulate(table, headers=[
42+
"Module", "Name", "Exam", "Semester", "Description", "Grade"]))
43+
elif args.output == "json":
44+
import json
45+
out = []
46+
for module in s.modules:
47+
for exam in s.get_exams_for_module(module):
48+
out.append({"module": module.num, "name": module.name, "exam": exam.name,
49+
"semester": exam.semester, "description": exam.description, "grade": exam.grade})
50+
print(json.dumps(out, indent=4))
51+
elif args.output == "csv":
52+
import csv
53+
import sys
54+
out = [["Module", "Name", "Exam", "Semester", "Description", "Grade"]]
55+
for module in s.modules:
56+
for exam in s.get_exams_for_module(module):
57+
out.append([module.num, module.name, exam.name,
58+
exam.semester, exam.description, exam.grade])
59+
writer = csv.writer(sys.stdout)
60+
writer.writerows(out)

utils/print_exams_as_table.py

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)