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",
|
"https://www.googleapis.com/auth/calendar.events",
|
||||||
]
|
]
|
||||||
|
|
||||||
CALENDAR_ID = "40e4v6t1s2spr9f1d9d45br3ik@group.calendar.google.com"
|
|
||||||
|
|
||||||
|
|
||||||
class CalendarService:
|
class CalendarService:
|
||||||
service: Resource
|
service: Resource
|
||||||
@ -47,7 +45,7 @@ class CalendarService:
|
|||||||
return creds
|
return creds
|
||||||
|
|
||||||
def insert_or_update_event(
|
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_id = b32hexencode(id.encode("ascii")).decode("ascii").lower().rstrip("=")
|
||||||
event = {
|
event = {
|
||||||
@ -65,14 +63,14 @@ class CalendarService:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
self.service.events().update(
|
self.service.events().update(
|
||||||
calendarId=CALENDAR_ID, eventId=event_id, body=event
|
calendarId=calendar_id, eventId=event_id, body=event
|
||||||
).execute()
|
).execute()
|
||||||
|
|
||||||
except HttpError as error:
|
except HttpError as error:
|
||||||
# Create event if it doesn't exist
|
# Create event if it doesn't exist
|
||||||
if error.status_code == 404:
|
if error.status_code == 404:
|
||||||
self.service.events().insert(
|
self.service.events().insert(
|
||||||
calendarId=CALENDAR_ID, body=event
|
calendarId=calendar_id, body=event
|
||||||
).execute()
|
).execute()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
5
main.py
5
main.py
@ -16,9 +16,12 @@ def get_printer_job(calendar, printer):
|
|||||||
seconds=current_job["progress"]["printTimeLeft"]
|
seconds=current_job["progress"]["printTimeLeft"]
|
||||||
)
|
)
|
||||||
print(current_job["job"]["file"]["name"], start, estimated_end)
|
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(
|
calendar.insert_or_update_event(
|
||||||
|
printer["calendar_id"],
|
||||||
f'OctoPrint Reservations: {printer["name"]}',
|
f'OctoPrint Reservations: {printer["name"]}',
|
||||||
event_name,
|
event_name,
|
||||||
start,
|
start,
|
||||||
|
Loading…
Reference in New Issue
Block a user