Skip to content

Commit

Permalink
tune up
Browse files Browse the repository at this point in the history
  • Loading branch information
morsecodist committed Jan 22, 2024
1 parent 5683957 commit cf749c3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
10 changes: 6 additions & 4 deletions google_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand All @@ -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': {
Expand Down Expand Up @@ -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()
13 changes: 5 additions & 8 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand All @@ -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():
Expand Down

0 comments on commit cf749c3

Please sign in to comment.