Move calendar ID and shop name into config file, per printer
This commit is contained in:
parent
f29a6170c1
commit
c4d79c9def
@ -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:
|
||||
|
5
main.py
5
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,
|
||||
|
Loading…
Reference in New Issue
Block a user