From b0f530a0c551c1cce3c1e9e35adb8e4ad22f2193 Mon Sep 17 00:00:00 2001 From: mroik Date: Mon, 21 Jun 2021 01:27:01 +0200 Subject: [PATCH] Added action for confirming the attendance Added this action 'cause I'm too lazy to confirm with my cellphone and scan the QR code (There's no connection outside the door) --- prenotazione_unimi/cmd.py | 14 ++++++++++++++ prenotazione_unimi/core/const.py | 1 + prenotazione_unimi/core/silab.py | 12 ++++++++++++ setup.py | 2 +- 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/prenotazione_unimi/cmd.py b/prenotazione_unimi/cmd.py index ad97bb7..2a34abd 100644 --- a/prenotazione_unimi/cmd.py +++ b/prenotazione_unimi/cmd.py @@ -306,6 +306,20 @@ def silab_penalty(args): print("Max bookings allowed:", maxbook) +@subcommand([ + argument( + "--room", "-r", type=int, required=True, + help="ID of the room to attend" + ) +]) +def confirm_silab(args): + if not args.username and not args.password: + raise ValueError("Username and password are required for this action") + lab = silab.SiLab() + lab.login(args.username, args.password) + print(lab.confirm_silab(args.room)) + + def main(): arguments = root.parse_args() arguments.func(arguments) diff --git a/prenotazione_unimi/core/const.py b/prenotazione_unimi/core/const.py index 6560b17..571ac8a 100644 --- a/prenotazione_unimi/core/const.py +++ b/prenotazione_unimi/core/const.py @@ -15,3 +15,4 @@ ENDPOINT_SILAB_LOGIN = "https://api.di.unimi.it/rooms/login" ENDPOINT_SILAB_BOOK = "https://api.di.unimi.it/rooms/book/1/" ENDPOINT_SILAB_UNBOOK = "https://api.di.unimi.it/rooms/unbook/1/" +ENDPOINT_SILAB_CONFIRM = "https://api.di.unimi.it/rooms/attend/" diff --git a/prenotazione_unimi/core/silab.py b/prenotazione_unimi/core/silab.py index 439755d..f57d34c 100644 --- a/prenotazione_unimi/core/silab.py +++ b/prenotazione_unimi/core/silab.py @@ -68,3 +68,15 @@ def get_penalty(self): assert resp.status_code == 200 resp = resp.json()["rooms"][0] return resp["absences"], resp["maxbookings"] + + def confirm_silab(self, room_id): + assert self.token is not None + resp = self.session.post( + const.ENDPOINT_SILAB_CONFIRM + str(room_id), + headers={ + "authorization": "Bearer " + self.token + } + ) + if resp.status_code != 200: + raise Exception("Something went wrong") + return resp.json()["longMessage"] diff --git a/setup.py b/setup.py index 7c3cab8..6bd2bd1 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="prenotazione-unimi", - version="1.1.3", + version="1.1.4", author="Mroik", author_email="mroik@delayed.space", description="Command line program that handles booking for lessons at UNIMI and other stuff.",