Les options c'est bon, surtout avec des champignons.
This commit is contained in:
parent
639f5a19a1
commit
9f9bda9189
2 changed files with 57 additions and 18 deletions
64
main.py
64
main.py
|
@ -42,6 +42,26 @@ from oauth2client import tools
|
||||||
from oauth2client.file import Storage
|
from oauth2client.file import Storage
|
||||||
|
|
||||||
import icalendar
|
import icalendar
|
||||||
|
import docopt
|
||||||
|
|
||||||
|
__doc__ = """
|
||||||
|
NTNOE cancer.
|
||||||
|
|
||||||
|
Because NTNOE is cancer, we had to do something to synchronise our Google
|
||||||
|
agenda on it.
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
ntnoe_cancer
|
||||||
|
ntnoe_cancer [--level=<l> --days-future=<df> --days-past=<dp>]
|
||||||
|
ntnoe_cancer -h | --help
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-h --help Show this screen.
|
||||||
|
--level=<l> Level of courses (0=all, 1=skip blue courses (! includes language courses), 2=skip everything but exams, for real man only) [default: 0]
|
||||||
|
--days-future=<df> Number of days in the future to look for the calendar [default: 15]
|
||||||
|
--days-past=<dp> Number of days in the past to look for the calendar, perfect for time travellers [default: 0]
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
DEBUG = False
|
DEBUG = False
|
||||||
APP_DIR = os.path.dirname(os.path.abspath(__file__))
|
APP_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
@ -99,13 +119,25 @@ class Event:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# ColorId corresponding to course code
|
# ColorId corresponding to course code
|
||||||
EVENT_COLOR = {
|
class Course:
|
||||||
'9': '9', # Amphi
|
AMPHI = '9'
|
||||||
'11': '10', # TL
|
TL = '11'
|
||||||
'10': '6', # TD
|
TD = '10'
|
||||||
'13': '5', # Autre
|
AUTRE = '13'
|
||||||
'12': '3', # Exam
|
EXAM = '12'
|
||||||
|
|
||||||
|
SKILL_LEVEL = {
|
||||||
|
'0' : {Course.AMPHI, Course.TL, Course.TD, Course.AUTRE, Course.EXAM},
|
||||||
|
'1' : {Course.TL, Course.TD, Course.AUTRE, Course.EXAM},
|
||||||
|
'2' : {Course.EXAM},
|
||||||
|
}
|
||||||
|
|
||||||
|
EVENT_COLOR = {
|
||||||
|
Course.AMPHI: '9',
|
||||||
|
Course.TL: '10',
|
||||||
|
Course.TD: '6',
|
||||||
|
Course.AUTRE: '5',
|
||||||
|
Course.EXAM: '3',
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, e):
|
def __init__(self, e):
|
||||||
|
@ -114,8 +146,8 @@ class Event:
|
||||||
self.start = e.decoded('DTSTART')
|
self.start = e.decoded('DTSTART')
|
||||||
self.end = e.decoded('DTEND')
|
self.end = e.decoded('DTEND')
|
||||||
self.location = e.decoded('LOCATION').decode('utf-8')
|
self.location = e.decoded('LOCATION').decode('utf-8')
|
||||||
self.colorid = self.EVENT_COLOR.get(
|
self.type = e.decoded('DESCRIPTION').decode('utf-8')
|
||||||
e.decoded('DESCRIPTION').decode('utf-8'), '1')
|
self.colorid = self.EVENT_COLOR.get(self.type, '1')
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.as_google())
|
return str(self.as_google())
|
||||||
|
@ -181,7 +213,7 @@ def get_ntnoe():
|
||||||
return r.content
|
return r.content
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main(arguments):
|
||||||
"""Get the events on NTNOE the puts them on Google Calendar.
|
"""Get the events on NTNOE the puts them on Google Calendar.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -213,7 +245,9 @@ def main():
|
||||||
ntnoe_calendar_id = created['id']
|
ntnoe_calendar_id = created['id']
|
||||||
|
|
||||||
now = datetime.datetime.now()
|
now = datetime.datetime.now()
|
||||||
then = now + TIMEDELTA_SYNCHRO
|
then = now + datetime.timedelta(days=int(arguments["--days-future"]))
|
||||||
|
before = now - datetime.timedelta(days=int(arguments["--days-past"]))
|
||||||
|
logger.info('Looking for events between {} and {}.'.format(before, then))
|
||||||
|
|
||||||
# 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.')
|
||||||
|
@ -228,12 +262,15 @@ def main():
|
||||||
eventId=event['id']
|
eventId=event['id']
|
||||||
).execute()
|
).execute()
|
||||||
|
|
||||||
logger.info('Adding new events.')
|
l = arguments['--level']
|
||||||
|
logger.info('Adding new events with skill={}.'.format(l))
|
||||||
|
granted_events = Event.SKILL_LEVEL[l]
|
||||||
for e in ical.walk('VEVENT'):
|
for e in ical.walk('VEVENT'):
|
||||||
event = Event(e)
|
event = Event(e)
|
||||||
if now >= event.end or event.start >= then:
|
if before >= event.end or event.start >= then:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if event.type in granted_events:
|
||||||
event = service.events().insert(
|
event = service.events().insert(
|
||||||
calendarId=ntnoe_calendar_id,
|
calendarId=ntnoe_calendar_id,
|
||||||
body=event.as_google()
|
body=event.as_google()
|
||||||
|
@ -242,4 +279,5 @@ def main():
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
arguments = docopt.docopt(__doc__, version='NTNOE Cancer 1.0')
|
||||||
|
main(arguments)
|
||||||
|
|
|
@ -14,3 +14,4 @@ rsa==3.4.2
|
||||||
six==1.11.0
|
six==1.11.0
|
||||||
uritemplate==3.0.0
|
uritemplate==3.0.0
|
||||||
urllib3==1.22
|
urllib3==1.22
|
||||||
|
docopt==0.6.2
|
||||||
|
|
Loading…
Reference in a new issue