summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rwxr-xr-xtimeoff.py78
2 files changed, 79 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..7c12220
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+*.xlsx
diff --git a/timeoff.py b/timeoff.py
new file mode 100755
index 0000000..2961d19
--- /dev/null
+++ b/timeoff.py
@@ -0,0 +1,78 @@
+#!/usr/bin/env python3
+
+import datetime
+import xlsxwriter
+
+PEOPLE = 'Ivan', 'Rod', 'Timo'
+# https://home.cern/official-holidays
+# https://home.cern/official-holidays-2024
+CERN_HOLIDAYS = frozenset({
+ datetime.date(2024, 1, 1),
+ datetime.date(2024, 3, 29),
+ datetime.date(2024, 4, 1),
+ datetime.date(2024, 5, 1),
+ datetime.date(2024, 5, 9),
+ datetime.date(2024, 5, 20),
+ datetime.date(2024, 9, 5),
+ datetime.date(2024, 12, 24),
+ datetime.date(2024, 12, 25),
+ datetime.date(2024, 12, 31),
+})
+CERN_CLOSURES = (
+ (datetime.date(2024, 12, 21), datetime.date(2025, 1, 5)),
+)
+START_DATE = datetime.date.today().replace(day=1)
+
+
+def main():
+ curdate = START_DATE
+ with xlsxwriter.Workbook('timeoff.xlsx') as workbook:
+ worksheet = workbook.add_worksheet('Time off')
+ worksheet.set_column(0, 0, 2.0)
+ worksheet.set_column(1, 1, 15.0)
+ worksheet.set_column(2, 32, 7.0)
+ worksheet.set_column(33, 33, 2.0)
+ worksheet.protect() # make 'locked' mean something
+ header = workbook.add_format({'bold': True, 'bg_color': '#bbbbbb'})
+ holiday = workbook.add_format({'bg_color': '#550011', 'color': 'white'})
+ editable = workbook.add_format({'locked': False})
+ end_date = START_DATE + datetime.timedelta(days=365)
+ rownum = 1
+
+ while curdate < end_date:
+ worksheet.write_string(rownum, 1, curdate.strftime('%B %Y'), header)
+ worksheet.write_string(rownum, 34, 'Total', header)
+ for i, person in enumerate(PEOPLE):
+ worksheet.write_string(rownum + i + 1, 1, person, header)
+ worksheet.write_formula(rownum + i + 1, 34, f'=SUM(C{rownum+i+2}:AG{rownum+i+2})', header)
+
+ curmonth = curdate.month
+ while curdate.month == curmonth:
+ worksheet.write_string(rownum, curdate.day + 1, curdate.strftime('%a %d'), header)
+
+ holiday_reason = None
+ if curdate in CERN_HOLIDAYS:
+ holiday_reason = 'holiday'
+ elif any(begin <= curdate <= end for begin, end in CERN_CLOSURES):
+ holiday_reason = 'closure'
+ elif curdate.weekday() in (5, 6):
+ holiday_reason = '' # blank text, but use holiday formatting, so not None
+ for i in range(len(PEOPLE)):
+ worksheet.write(rownum + i + 1, curdate.day + 1, holiday_reason,
+ editable if holiday_reason is None else holiday)
+
+ curdate += datetime.timedelta(days=1)
+
+ rownum += 2 + len(PEOPLE)
+
+ worksheet.conditional_format(1, 1, rownum, 33, {
+ 'type': 'cell', 'criteria': 'between', 'minimum': 0.5, 'maximum': 0.999,
+ 'format': workbook.add_format({'bg_color': '#3333ff', 'color': 'white'}),
+ })
+ worksheet.conditional_format(1, 1, rownum, 33, {
+ 'type': 'cell', 'criteria': '>=', 'value': 1,
+ 'format': workbook.add_format({'bg_color': 'navy', 'color': 'white'}),
+ })
+
+if __name__ == '__main__':
+ main()