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

View File

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

View File

@ -101,7 +101,7 @@ class Commands:
calendar.create(summary, timezone)
if 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:
""" add owner to calendar

View File

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