PEP8
This commit is contained in:
parent
dc5ce1186f
commit
24a80dff35
1 changed files with 7 additions and 14 deletions
21
main.py
21
main.py
|
@ -53,7 +53,7 @@ else:
|
||||||
if not os.path.exists(DATA_DIR):
|
if not os.path.exists(DATA_DIR):
|
||||||
os.makedirs(DATA_DIR)
|
os.makedirs(DATA_DIR)
|
||||||
|
|
||||||
##### Logger stuff #####
|
# Logger stuff
|
||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
@ -80,8 +80,6 @@ if DEBUG:
|
||||||
stream_handler.setFormatter(formatter)
|
stream_handler.setFormatter(formatter)
|
||||||
logger.addHandler(stream_handler)
|
logger.addHandler(stream_handler)
|
||||||
|
|
||||||
########################
|
|
||||||
|
|
||||||
|
|
||||||
TIMEDELTA_SYNCHRO = datetime.timedelta(days=15) # Number of days to look for
|
TIMEDELTA_SYNCHRO = datetime.timedelta(days=15) # Number of days to look for
|
||||||
# for synchronization
|
# for synchronization
|
||||||
|
@ -93,6 +91,7 @@ SCOPES = 'https://www.googleapis.com/auth/calendar'
|
||||||
CLIENT_SECRET_FILE = 'client_secret.json'
|
CLIENT_SECRET_FILE = 'client_secret.json'
|
||||||
APPLICATION_NAME = 'Google Calendar API Python Quickstart'
|
APPLICATION_NAME = 'Google Calendar API Python Quickstart'
|
||||||
|
|
||||||
|
|
||||||
class Event:
|
class Event:
|
||||||
"""
|
"""
|
||||||
The event class allows a simple convertion between `icalendar.cal.Event`
|
The event class allows a simple convertion between `icalendar.cal.Event`
|
||||||
|
@ -172,7 +171,7 @@ def get_ntnoe():
|
||||||
"""Retrieves the calendar on NTNOE."""
|
"""Retrieves the calendar on NTNOE."""
|
||||||
r = requests.post(
|
r = requests.post(
|
||||||
"https://ntnoe.metz.supelec.fr/ical/index.php",
|
"https://ntnoe.metz.supelec.fr/ical/index.php",
|
||||||
data={"envoyer":"Utf8_All","submit":"G%E9n%E9rer"},
|
data={"envoyer": "Utf8_All", "submit": "G%E9n%E9rer"},
|
||||||
auth=(NTNOE_ID, NTNOE_PASS),
|
auth=(NTNOE_ID, NTNOE_PASS),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -181,6 +180,7 @@ def get_ntnoe():
|
||||||
r = requests.get(url, auth=(NTNOE_ID, NTNOE_PASS))
|
r = requests.get(url, auth=(NTNOE_ID, NTNOE_PASS))
|
||||||
return r.content
|
return r.content
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Get the events on NTNOE the puts them on Google Calendar.
|
"""Get the events on NTNOE the puts them on Google Calendar.
|
||||||
"""
|
"""
|
||||||
|
@ -206,15 +206,14 @@ def main():
|
||||||
if not ntnoe_calendar_id:
|
if not ntnoe_calendar_id:
|
||||||
logger.info("Creating `ntnoe` calendar...")
|
logger.info("Creating `ntnoe` calendar...")
|
||||||
created = service.calendars().insert(body={
|
created = service.calendars().insert(body={
|
||||||
'defaultReminders' : [],
|
'defaultReminders': [],
|
||||||
'selected' : True,
|
'selected': True,
|
||||||
'summary' : 'ntnoe',
|
'summary': 'ntnoe',
|
||||||
}).execute()
|
}).execute()
|
||||||
ntnoe_calendar_id = created['id']
|
ntnoe_calendar_id = created['id']
|
||||||
|
|
||||||
now = datetime.datetime.now()
|
now = datetime.datetime.now()
|
||||||
then = now + TIMEDELTA_SYNCHRO
|
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.
|
# NTNOE calendar often changes. So let's delete former synchronizations.
|
||||||
logger.info('Deleting former events.')
|
logger.info('Deleting former events.')
|
||||||
|
@ -232,12 +231,6 @@ def main():
|
||||||
logger.info('Adding new events.')
|
logger.info('Adding new events.')
|
||||||
for e in ical.walk('VEVENT'):
|
for e in ical.walk('VEVENT'):
|
||||||
event = Event(e)
|
event = Event(e)
|
||||||
t = (
|
|
||||||
event.summary,
|
|
||||||
event.start.isoformat(),
|
|
||||||
event.end.isoformat(),
|
|
||||||
event.location
|
|
||||||
)
|
|
||||||
if now >= event.end or event.start >= then:
|
if now >= event.end or event.start >= then:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue