commit f05522a2d6c762b264a6bcc712fb055f0a24825e Author: Nicolas Duhamel Date: Fri Mar 1 22:21:10 2019 +0100 Initial diff --git a/icalendar b/icalendar new file mode 160000 index 0000000..1943386 --- /dev/null +++ b/icalendar @@ -0,0 +1 @@ +Subproject commit 194338629370ada3a2978c42bbe85529f8012d3d diff --git a/main.py b/main.py new file mode 100644 index 0000000..dd94bc9 --- /dev/null +++ b/main.py @@ -0,0 +1,92 @@ +import uuid +import datetime +import os +import argparse +import calendar + +import pytz +import icalendar + +TZ = pytz.timezone('Europe/Paris') + +WEEKDAY = { + 0: "Lundi", + 1: "Mardi", + 2: "Mercredi", + 3: "Jeudi", + 4: "Vendredi", + 5: "Samedi", + 6: "Dimanche" +} + +SCHEDULE = { + "day1": { + "summary": "jour 8h", + "start": (8,0), + "end": (16,15) }, + "day2": { + "summary": "jour 9h", + "start": (9,0), + "end": (18,0) }, + "morning": { + "summary": "matin", + "start": (6,30), + "end": (14,15) }, + "afternoon": { + "summary": "Apres-midi", + "start": (13,45), + "end": (21,15),} +} + +def get_weekday(year, month, day): + wd = calendar.weekday(i[0],i[1],i[2]) + return WEEKDAY[wd] + +def generate_ical(date, schedule_info): + uid = uuid.uuid4() + cal = icalendar.Calendar() + cal.add('prodid', '-//Schedule generator//') + cal.add('version', '2.0') + + event = icalendar.Event() + event.add('uid', uid) + event.add('summary', schedule_info["summary"]) + event.add('dtstart', datetime.datetime(date[0],date[1],date[2],\ + schedule_info['start'][0], schedule_info['start'][1],tzinfo=TZ)) + + event.add('dtend', datetime.datetime(date[0],date[1],date[2],\ + schedule_info['end'][0], schedule_info['end'][1],tzinfo=TZ)) + event.add('dtstamp', datetime.datetime.now(tz=TZ)) + + cal.add_component(event) + return (uid, cal) + +parser = argparse.ArgumentParser() +parser.add_argument("month", type=int, help="choose month to create or edit as integer") +args = parser.parse_args() + +schedule = [] + +switch_case = { + "j": SCHEDULE["day1"], + "k": SCHEDULE["day2"], + "m": SCHEDULE["morning"], + "a": SCHEDULE["afternoon"] +} + +for i in calendar.Calendar().itermonthdays3(2019, args.month): + if i[1] == args.month: + while True: + txt = "%s %s\n(J)our 8h, (K)Jour 9h, (M)atin, (A)pres-midi, (R)epos:" % (get_weekday(*i), i[2]) + choose = input(txt) + if choose in switch_case.keys(): + schedule.append((i, switch_case[choose])) + break + elif choose == 'r': + break + +for evt in schedule: + (uid, cal) = generate_ical(*evt) + f = open('%s.ics' % uid, 'wb') + f.write(cal.to_ical()) + f.close()