This commit is contained in:
Nicolas Duhamel 2019-03-01 22:21:10 +01:00
commit f05522a2d6
2 changed files with 93 additions and 0 deletions

1
icalendar Submodule

@ -0,0 +1 @@
Subproject commit 194338629370ada3a2978c42bbe85529f8012d3d

92
main.py Normal file
View File

@ -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()