Move calendar event ID encoding to method

This commit is contained in:
Adam Goldsmith 2022-04-02 19:01:08 -04:00
parent d81a17ef61
commit 50a2231174

View File

@ -22,6 +22,10 @@ class CalendarService:
creds = self._authenticate() creds = self._authenticate()
self.service = build("calendar", "v3", credentials=creds) self.service = build("calendar", "v3", credentials=creds)
@staticmethod
def encode_event_id(id):
return b16encode(id.encode("ascii")).decode("ascii").lower().rstrip("=")
def _authenticate(self) -> Credentials: def _authenticate(self) -> Credentials:
creds = None creds = None
# The file token.json stores the user's access and refresh tokens, and is # The file token.json stores the user's access and refresh tokens, and is
@ -47,8 +51,7 @@ class CalendarService:
def insert_or_update_event( def insert_or_update_event(
self, calendar_id: str, id: str, title: str, start: datetime, end: datetime self, calendar_id: str, id: str, title: str, start: datetime, end: datetime
): ):
event_id = b16encode(id.encode("ascii")).decode("ascii").lower().rstrip("=") event_id = self.encode_event_id(id)
print(event_id)
event = { event = {
"id": event_id, "id": event_id,
"summary": title, "summary": title,