Skip to content
This repository has been archived by the owner on May 28, 2023. It is now read-only.

Commit

Permalink
Added action for confirming the attendance
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
Mroik committed Jun 20, 2021
1 parent 510065e commit b0f530a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
14 changes: 14 additions & 0 deletions prenotazione_unimi/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions prenotazione_unimi/core/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
12 changes: 12 additions & 0 deletions prenotazione_unimi/core/silab.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="prenotazione-unimi",
version="1.1.3",
version="1.1.4",
author="Mroik",
author_email="[email protected]",
description="Command line program that handles booking for lessons at UNIMI and other stuff.",
Expand Down

0 comments on commit b0f530a

Please sign in to comment.