fix var names

This commit is contained in:
Dmitry Belyaev 2022-02-24 12:20:07 +03:00
parent 839a3ac0c3
commit 38fe634a9f
Signed by: b4tman
GPG Key ID: 41A00BF15EA7E5F3
4 changed files with 25 additions and 25 deletions

View File

@ -90,9 +90,9 @@ class GoogleCalendar:
logger = logging.getLogger('GoogleCalendar') logger = logging.getLogger('GoogleCalendar')
def __init__(self, service: discovery.Resource, calendarId: Optional[str]): def __init__(self, service: discovery.Resource, calendar_id: Optional[str]):
self.service: discovery.Resource = service self.service: discovery.Resource = service
self.calendarId: str = calendarId self.calendar_id: str = calendar_id
def _make_request_callback(self, action: str, events_by_req: EventList) -> Callable: def _make_request_callback(self, action: str, events_by_req: EventList) -> Callable:
"""make callback for log result of batch request """make callback for log result of batch request
@ -130,13 +130,13 @@ class GoogleCalendar:
fields = 'nextPageToken,items(id,iCalUID,updated)' fields = 'nextPageToken,items(id,iCalUID,updated)'
events = [] events = []
page_token = None page_token = None
timeMin = utc.normalize(start.astimezone(utc)).replace( time_min = utc.normalize(start.astimezone(utc)).replace(
tzinfo=None).isoformat() + 'Z' tzinfo=None).isoformat() + 'Z'
while True: while True:
response = self.service.events().list(calendarId=self.calendarId, response = self.service.events().list(calendarId=self.calendar_id,
pageToken=page_token, pageToken=page_token,
singleEvents=True, singleEvents=True,
timeMin=timeMin, timeMin=time_min,
fields=fields).execute() fields=fields).execute()
if 'items' in response: if 'items' in response:
events.extend(response['items']) events.extend(response['items'])
@ -181,7 +181,7 @@ class GoogleCalendar:
i = 0 i = 0
for event in events: for event in events:
events_by_req.append(event) events_by_req.append(event)
batch.add(self.service.events().list(calendarId=self.calendarId, batch.add(self.service.events().list(calendarId=self.calendar_id,
iCalUID=event['iCalUID'], iCalUID=event['iCalUID'],
showDeleted=True, showDeleted=True,
fields=fields fields=fields
@ -210,7 +210,7 @@ class GoogleCalendar:
for event in events: for event in events:
events_by_req.append(event) events_by_req.append(event)
batch.add(self.service.events().insert( batch.add(self.service.events().insert(
calendarId=self.calendarId, body=event, fields=fields), calendarId=self.calendar_id, body=event, fields=fields),
request_id=str(i) request_id=str(i)
) )
i += 1 i += 1
@ -234,7 +234,7 @@ class GoogleCalendar:
continue continue
events_by_req.append(event_new) events_by_req.append(event_new)
batch.add(self.service.events().patch( batch.add(self.service.events().patch(
calendarId=self.calendarId, eventId=event_old['id'], calendarId=self.calendar_id, eventId=event_old['id'],
body=event_new), fields=fields, request_id=str(i)) body=event_new), fields=fields, request_id=str(i))
i += 1 i += 1
batch.execute() batch.execute()
@ -257,7 +257,7 @@ class GoogleCalendar:
continue continue
events_by_req.append(event_new) events_by_req.append(event_new)
batch.add(self.service.events().update( batch.add(self.service.events().update(
calendarId=self.calendarId, eventId=event_old['id'], calendarId=self.calendar_id, eventId=event_old['id'],
body=event_new, fields=fields), request_id=str(i)) body=event_new, fields=fields), request_id=str(i))
i += 1 i += 1
batch.execute() batch.execute()
@ -277,12 +277,12 @@ class GoogleCalendar:
for event in events: for event in events:
events_by_req.append(event) events_by_req.append(event)
batch.add(self.service.events().delete( batch.add(self.service.events().delete(
calendarId=self.calendarId, calendarId=self.calendar_id,
eventId=event['id']), request_id=str(i)) eventId=event['id']), request_id=str(i))
i += 1 i += 1
batch.execute() batch.execute()
def create(self, summary: str, timeZone: Optional[str] = None) -> Any: def create(self, summary: str, time_zone: Optional[str] = None) -> Any:
"""create calendar """create calendar
Arguments: Arguments:
@ -296,20 +296,20 @@ class GoogleCalendar:
""" """
calendar = {'summary': summary} calendar = {'summary': summary}
if timeZone is not None: if time_zone is not None:
calendar['timeZone'] = timeZone calendar['timeZone'] = time_zone
created_calendar = self.service.calendars().insert( created_calendar = self.service.calendars().insert(
body=calendar body=calendar
).execute() ).execute()
self.calendarId = created_calendar['id'] self.calendar_id = created_calendar['id']
return created_calendar return created_calendar
def delete(self): def delete(self):
"""delete calendar """delete calendar
""" """
self.service.calendars().delete(calendarId=self.calendarId).execute() self.service.calendars().delete(calendarId=self.calendar_id).execute()
def make_public(self): def make_public(self):
"""make calendar puplic """make calendar puplic
@ -322,7 +322,7 @@ class GoogleCalendar:
'role': 'reader' 'role': 'reader'
} }
return self.service.acl().insert( return self.service.acl().insert(
calendarId=self.calendarId, calendarId=self.calendar_id,
body=rule_public body=rule_public
).execute() ).execute()
@ -341,6 +341,6 @@ class GoogleCalendar:
'role': 'owner' 'role': 'owner'
} }
return self.service.acl().insert( return self.service.acl().insert(
calendarId=self.calendarId, calendarId=self.calendar_id,
body=rule_owner body=rule_owner
).execute() ).execute()

View File

@ -29,10 +29,10 @@ def format_datetime_utc(value: DateDateTime) -> str:
).replace(tzinfo=None).isoformat() + 'Z' ).replace(tzinfo=None).isoformat() + 'Z'
def gcal_date_or_dateTime(value: DateDateTime, def gcal_date_or_datetime(value: DateDateTime,
check_value: Optional[DateDateTime] = None) \ check_value: Optional[DateDateTime] = None) \
-> Dict[str, str]: -> Dict[str, str]:
"""date or dateTime to gcal (start or end dict) """date or datetime to gcal (start or end dict)
Arguments: Arguments:
value: date or datetime value: date or datetime
@ -96,7 +96,7 @@ class EventConverter(Event):
""" """
value = self.decoded('DTSTART') value = self.decoded('DTSTART')
return gcal_date_or_dateTime(value) return gcal_date_or_datetime(value)
def _gcal_end(self) -> Dict[str, str]: def _gcal_end(self) -> Dict[str, str]:
"""event end dict from icalendar event """event end dict from icalendar event
@ -110,13 +110,13 @@ class EventConverter(Event):
result = None result = None
if 'DTEND' in self: if 'DTEND' in self:
value = self.decoded('DTEND') value = self.decoded('DTEND')
result = gcal_date_or_dateTime(value) result = gcal_date_or_datetime(value)
elif 'DURATION' in self: elif 'DURATION' in self:
start_val = self.decoded('DTSTART') start_val = self.decoded('DTSTART')
duration = self.decoded('DURATION') duration = self.decoded('DURATION')
end_val = start_val + duration end_val = start_val + duration
result = gcal_date_or_dateTime(end_val, check_value=start_val) result = gcal_date_or_datetime(end_val, check_value=start_val)
else: else:
raise ValueError('no DTEND or DURATION') raise ValueError('no DTEND or DURATION')
return result return result

View File

@ -101,7 +101,7 @@ class Commands:
calendar.create(summary, timezone) calendar.create(summary, timezone)
if public: if public:
calendar.make_public() calendar.make_public()
print('{}: {}'.format(summary, calendar.calendarId)) print('{}: {}'.format(summary, calendar.calendar_id))
def add_owner(self, calendar_id: str, email: str) -> None: def add_owner(self, calendar_id: str, email: str) -> None:
""" add owner to calendar """ add owner to calendar

View File

@ -38,7 +38,7 @@ def main():
if 'logging' in config: if 'logging' in config:
logging.config.dictConfig(config['logging']) logging.config.dictConfig(config['logging'])
calendarId: str = config['calendar']['google_id'] calendar_id: str = config['calendar']['google_id']
ics_filepath: str = config['calendar']['source'] ics_filepath: str = config['calendar']['source']
start = get_start_date(config['start_from']) start = get_start_date(config['start_from'])
@ -47,7 +47,7 @@ def main():
converter.load(ics_filepath) converter.load(ics_filepath)
service = GoogleCalendarService.from_config(config) service = GoogleCalendarService.from_config(config)
gcalendar = GoogleCalendar(service, calendarId) gcalendar = GoogleCalendar(service, calendar_id)
sync = CalendarSync(gcalendar, converter) sync = CalendarSync(gcalendar, converter)
sync.prepare_sync(start) sync.prepare_sync(start)