From 54146451c778a6d10df0c32e44cbeb1ffd7483b0 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Sat, 4 Jun 2022 00:39:29 +0300 Subject: [PATCH] types: + EventsSearchResults --- sync_ics2gcal/gcal.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/sync_ics2gcal/gcal.py b/sync_ics2gcal/gcal.py index d1059f2..45120b9 100644 --- a/sync_ics2gcal/gcal.py +++ b/sync_ics2gcal/gcal.py @@ -11,6 +11,7 @@ from typing import ( TypedDict, TypeAlias, Literal, + NamedTuple, ) import google.auth @@ -84,6 +85,11 @@ EventList: TypeAlias = List[EventData] EventTuple: TypeAlias = Tuple[EventData, EventData] +class EventsSearchResults(NamedTuple): + exists: List[EventTuple] + new: List[EventData] + + class GoogleCalendarService: """class for make google calendar service Resource @@ -227,14 +233,14 @@ class GoogleCalendar: self.logger.info("%d events listed", len(events)) return events - def find_exists(self, events: List) -> Tuple[List[EventTuple], EventList]: + def find_exists(self, events: List) -> EventsSearchResults: """find existing events from list, by 'iCalUID' field Arguments: events {list} -- list of events Returns: - tuple -- (events_exist, events_not_found) + EventsSearchResults -- (events_exist, events_not_found) events_exist - list of tuples: (new_event, exists_event) """ @@ -277,7 +283,7 @@ class GoogleCalendar: i += 1 batch.execute() self.logger.info("%d events exists, %d not found", len(exists), len(not_found)) - return exists, not_found + return EventsSearchResults(exists, not_found) def insert_events(self, events: EventList): """insert list of events