Skip to content

Instantly share code, notes, and snippets.

@bodokaiser
Created May 14, 2020 10:40
Show Gist options
  • Save bodokaiser/0cef865f110f47c05143c7668bc99b71 to your computer and use it in GitHub Desktop.
Save bodokaiser/0cef865f110f47c05143c7668bc99b71 to your computer and use it in GitHub Desktop.
from datetime import date, timedelta
from dateutil import rrule
from shutil import copyfile
# start and end time of your work contract
start = date(2020, 3, 1)
end = date(2020, 8, 31)
# TODO: check if workday is public holiday
holidays = [
# Karfreitag
date(2020, 4, 10),
# Ostermontag
date(2020, 4, 13),
# Tag der Arbeit
date(2020, 5, 1),
# Christi Himmelfahrt
date(2020, 5, 21),
# Pfingstmontag
date(2020, 6, 1),
# Fronleichnam
date(2020, 6, 11),
]
template = 'template.pdf'
def next_monday(dt):
return dt + timedelta(days=(7 - dt.weekday()))
def prev_monday(dt):
return dt - timedelta(days=(7 - dt.weekday()))
def week_number(dt):
return dt.isocalendar()[1]
for monday in rrule.rrule(rrule.WEEKLY, dtstart=next_monday(start), until=prev_monday(end)):
workdays = [monday + timedelta(days=1), monday + timedelta(days=2)]
for holiday in holidays:
if any([workday.date() == holiday for workday in workdays]):
raise RuntimeError(f'You should not work on {holiday}!')
friday = monday + timedelta(days=4)
sunday = monday + timedelta(days=6)
# copy template file to KWxy.pdf where xy indicates the week number
copyfile(template, f'KW{week_number(monday)}.pdf')
print(
f'Monday: {monday.date()}, Friday: {friday.date()}, Sunday: {sunday.date()}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment