Move calendar ID and shop name into config file, per printer

This commit is contained in:
Adam Goldsmith 2021-12-28 00:04:08 -05:00
parent f29a6170c1
commit c4d79c9def
2 changed files with 7 additions and 6 deletions

View File

@ -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:

View File

@ -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,