From cf749c30be2d23c29c1426176c901911385fbd48 Mon Sep 17 00:00:00 2001 From: Todd Morse Date: Mon, 22 Jan 2024 08:43:18 -0500 Subject: [PATCH] tune up --- google_calendar.py | 10 ++++++---- main.py | 13 +++++-------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/google_calendar.py b/google_calendar.py index 5dcfe94..819c319 100644 --- a/google_calendar.py +++ b/google_calendar.py @@ -3,8 +3,8 @@ import os.path from base64 import b64decode, b64encode from tempfile import NamedTemporaryFile -from datetime import datetime, timedelta, timezone -from typing import Dict +from datetime import datetime, timedelta +from typing import Any, Dict from google.auth.transport.requests import Request from google.oauth2.credentials import Credentials @@ -26,6 +26,8 @@ creds.refresh(Request()) # https://developers.google.com/calendar/api/quickstart/python service = build('calendar', 'v3', credentials=creds) +else: + raise Exception() def get_token(credentials_filename: str): @@ -48,7 +50,7 @@ def next_n_events(n=100): return events_result.get('items', []) -def upsert_event(calendar_id: str, summary: str, start: datetime, end: datetime, description: str, existing_event: Dict[str, any] | None): +def upsert_event(calendar_id: str, summary: str, start: datetime, end: datetime, description: str, existing_event: Dict[str, Any] | None): event = { 'summary': summary, 'start': { @@ -80,5 +82,5 @@ def upsert_event(calendar_id: str, summary: str, start: datetime, end: datetime, return service.events().insert(calendarId=CALENDAR_ID, body=event).execute() -def delete_event(existing_event: Dict[str, any]): +def delete_event(existing_event: Dict[str, Any]): service.events().delete(calendarId=CALENDAR_ID, eventId=existing_event['id']).execute() diff --git a/main.py b/main.py index 00d9b57..dbade1f 100644 --- a/main.py +++ b/main.py @@ -38,8 +38,7 @@ class Event(NamedTuple): end_time: datetime agenda_link: str | None zoom_link: str | None - summary: str | None - description: str | None + description: str demo = """ # Name of Meeting in Title Case Followed by Agenda @@ -87,7 +86,7 @@ async def download_and_parse_pdf(url: str): return extract_text_from_pdf(io.BytesIO(await response.read())) else: print(f"Error: {response.status}") - return None + return [] def extract_text_from_pdf(data: io.BytesIO): @@ -139,9 +138,7 @@ async def build_event(event: dict) -> Event: existing_meeting = meetings.get((name, start_time.isoformat())) agenda_file_id = get_agenda_file_id(event) - agenda_link = None - zoom_link = None - summary = None + agenda_link = zoom_link = None description = DEFAULT_DESCRIPTION if agenda_file_id and (not existing_meeting or DEFAULT_DESCRIPTION in existing_meeting['description']): agenda_link = get_file_download_link(agenda_file_id) @@ -156,10 +153,10 @@ async def build_event(event: dict) -> Event: description += f"## [Join Meeting]({zoom_link})\n" else: description += "## Link to Join Unavailable\n" - description += summary + description += summary or "" description = markdown.markdown(description) - return Event(_id, event, name, start_time, end_time, agenda_link, zoom_link, summary, description) + return Event(_id, event, name, start_time, end_time, agenda_link, zoom_link, description) async def main():