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):
|
||||
os.makedirs(DATA_DIR)
|
||||
|
||||
##### Logger stuff #####
|
||||
# Logger stuff
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
@ -80,8 +80,6 @@ if DEBUG:
|
|||
stream_handler.setFormatter(formatter)
|
||||
logger.addHandler(stream_handler)
|
||||
|
||||
########################
|
||||
|
||||
|
||||
TIMEDELTA_SYNCHRO = datetime.timedelta(days=15) # Number of days to look for
|
||||
# for synchronization
|
||||
|
@ -93,6 +91,7 @@ SCOPES = 'https://www.googleapis.com/auth/calendar'
|
|||
CLIENT_SECRET_FILE = 'client_secret.json'
|
||||
APPLICATION_NAME = 'Google Calendar API Python Quickstart'
|
||||
|
||||
|
||||
class Event:
|
||||
"""
|
||||
The event class allows a simple convertion between `icalendar.cal.Event`
|
||||
|
@ -172,7 +171,7 @@ def get_ntnoe():
|
|||
"""Retrieves the calendar on NTNOE."""
|
||||
r = requests.post(
|
||||
"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),
|
||||
)
|
||||
|
||||
|
@ -181,6 +180,7 @@ def get_ntnoe():
|
|||
r = requests.get(url, auth=(NTNOE_ID, NTNOE_PASS))
|
||||
return r.content
|
||||
|
||||
|
||||
def main():
|
||||
"""Get the events on NTNOE the puts them on Google Calendar.
|
||||
"""
|
||||
|
@ -206,15 +206,14 @@ def main():
|
|||
if not ntnoe_calendar_id:
|
||||
logger.info("Creating `ntnoe` calendar...")
|
||||
created = service.calendars().insert(body={
|
||||
'defaultReminders' : [],
|
||||
'selected' : True,
|
||||
'summary' : 'ntnoe',
|
||||
'defaultReminders': [],
|
||||
'selected': True,
|
||||
'summary': 'ntnoe',
|
||||
}).execute()
|
||||
ntnoe_calendar_id = created['id']
|
||||
|
||||
now = datetime.datetime.now()
|
||||
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.')
|
||||
|
@ -232,12 +231,6 @@ def main():
|
|||
logger.info('Adding new events.')
|
||||
for e in ical.walk('VEVENT'):
|
||||
event = Event(e)
|
||||
t = (
|
||||
event.summary,
|
||||
event.start.isoformat(),
|
||||
event.end.isoformat(),
|
||||
event.location
|
||||
)
|
||||
if now >= event.end or event.start >= then:
|
||||
continue
|
||||
|
||||
|
|
Loading…
Reference in a new issue