Browse Source

logger

master
Klafyvel 8 years ago
parent
commit
6ff0c4e1a0
  1. 12
      main.py

12
main.py

@ -185,12 +185,19 @@ def get_ntnoe():
def main():
"""Get the events on NTNOE the puts them on Google Calendar.
"""
# Authentication on google
logger.info('Authenticating on Google')
credentials = get_credentials()
http = credentials.authorize(httplib2.Http())
service = discovery.build('calendar', 'v3', http=http)
# Retrieving the calendar on NTNOE
logger.info('Requesting NTNOE for {}'.format(NTNOE_ID))
ical = icalendar.Calendar.from_ical(get_ntnoe())
# We need to find the id of the calendar we will edit.
logger.info('Looking for `ntnoe` calendar.')
calendars = service.calendarList().list().execute()
ntnoe_calendar_id = None
for c in calendars['items']:
@ -198,7 +205,7 @@ def main():
ntnoe_calendar_id = c['id']
if not ntnoe_calendar_id:
logger.info("Creating ntnoe calendar...")
logger.info("Creating `ntnoe` calendar...")
created = service.calendars().insert(body={
'defaultReminders' : [],
'selected' : True,
@ -210,6 +217,8 @@ def main():
then = now + TIMEDELTA_SYNCHRO
time_search = datetime.datetime(now.year, now.month, now.day, 1)
# NTNOE calendar often changes. So let's delete former synchronizations.
logger.info('Deleting former events.')
former_ones = service.events().list(
calendarId=ntnoe_calendar_id,
).execute()
@ -221,6 +230,7 @@ def main():
eventId=event['id']
).execute()
logger.info('Adding new events.')
for e in ical.walk('VEVENT'):
event = Event(e)
t = (

Loading…
Cancel
Save