types: + EventsSearchResults

This commit is contained in:
Dmitry Belyaev 2022-06-04 00:39:29 +03:00
parent 5b4dca0ab9
commit 54146451c7
Signed by: b4tman
GPG Key ID: 41A00BF15EA7E5F3
1 changed files with 9 additions and 3 deletions

View File

@ -11,6 +11,7 @@ from typing import (
TypedDict, TypedDict,
TypeAlias, TypeAlias,
Literal, Literal,
NamedTuple,
) )
import google.auth import google.auth
@ -84,6 +85,11 @@ EventList: TypeAlias = List[EventData]
EventTuple: TypeAlias = Tuple[EventData, EventData] EventTuple: TypeAlias = Tuple[EventData, EventData]
class EventsSearchResults(NamedTuple):
exists: List[EventTuple]
new: List[EventData]
class GoogleCalendarService: class GoogleCalendarService:
"""class for make google calendar service Resource """class for make google calendar service Resource
@ -227,14 +233,14 @@ class GoogleCalendar:
self.logger.info("%d events listed", len(events)) self.logger.info("%d events listed", len(events))
return 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 """find existing events from list, by 'iCalUID' field
Arguments: Arguments:
events {list} -- list of events events {list} -- list of events
Returns: Returns:
tuple -- (events_exist, events_not_found) EventsSearchResults -- (events_exist, events_not_found)
events_exist - list of tuples: (new_event, exists_event) events_exist - list of tuples: (new_event, exists_event)
""" """
@ -277,7 +283,7 @@ class GoogleCalendar:
i += 1 i += 1
batch.execute() batch.execute()
self.logger.info("%d events exists, %d not found", len(exists), len(not_found)) 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): def insert_events(self, events: EventList):
"""insert list of events """insert list of events