From c4d79c9defc46284cf067c966b1b40cc552e96e3 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Tue, 28 Dec 2021 00:04:08 -0500 Subject: [PATCH] Move calendar ID and shop name into config file, per printer --- google_calendar.py | 8 +++----- main.py | 5 ++++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/google_calendar.py b/google_calendar.py index 614dd7b..b4bda49 100644 --- a/google_calendar.py +++ b/google_calendar.py @@ -14,8 +14,6 @@ SCOPES = [ "https://www.googleapis.com/auth/calendar.events", ] -CALENDAR_ID = "40e4v6t1s2spr9f1d9d45br3ik@group.calendar.google.com" - class CalendarService: service: Resource @@ -47,7 +45,7 @@ class CalendarService: return creds def insert_or_update_event( - self, id: str, title: str, start: datetime, end: datetime + self, calendar_id: str, id: str, title: str, start: datetime, end: datetime ): event_id = b32hexencode(id.encode("ascii")).decode("ascii").lower().rstrip("=") event = { @@ -65,14 +63,14 @@ class CalendarService: try: self.service.events().update( - calendarId=CALENDAR_ID, eventId=event_id, body=event + calendarId=calendar_id, eventId=event_id, body=event ).execute() except HttpError as error: # Create event if it doesn't exist if error.status_code == 404: self.service.events().insert( - calendarId=CALENDAR_ID, body=event + calendarId=calendar_id, body=event ).execute() else: diff --git a/main.py b/main.py index 5e2a4b7..c032c33 100644 --- a/main.py +++ b/main.py @@ -16,9 +16,12 @@ def get_printer_job(calendar, printer): seconds=current_job["progress"]["printTimeLeft"] ) print(current_job["job"]["file"]["name"], start, estimated_end) - event_name = f'{current_job["job"]["user"]} | Digital Fabrication and Electronics Lab - {printer["name"]}' + event_name = ( + f'{current_job["job"]["user"]} | {printer["shop"]} - {printer["name"]}' + ) calendar.insert_or_update_event( + printer["calendar_id"], f'OctoPrint Reservations: {printer["name"]}', event_name, start,