import datetime as dt def add2dict(datadict, d): cw = d.isocalendar()[1] y = d.isocalendar()[0] # to avoid last days of year being mapped into first calender week of same year ts = d.strftime('%a., %d.%m.%Y') if y not in datadict.keys(): datadict[y] = {} if cw not in datadict[y].keys(): datadict[y][cw] = [] datadict[y][cw].append(ts) return year = 2025 firstday = dt.datetime(year, 11, 17) lastday = dt.datetime(year, 12, 31) datadict = {} d = firstday while d != lastday + dt.timedelta(days=1): add2dict(datadict, d) d = d + dt.timedelta(days=1) for cw in datadict[year]: print('### KW{:02}'.format(cw)) print('{{ScheduleTableHead()}}') for ts in datadict[year][cw]: print('| **{:}** {{_}} |'.format(ts)) # print('| `00:00 - 24:00` | {{TunnelFr}} | Shutdown | {{Juri}} and {{Elmar}} |') # if ts[:4] in ['Sat.', 'Sun.']: # print('| `00:00 - 24:00` | {{Unstable}} | Vacuum scrubbing | OP shift crew |') # else: # print('| `00:00 - 07:00` | {{Unstable}} | Vacuum scrubbing | OP shift crew |') # print('| `07:00 - 24:00` | {{Unstable}} | Phase 2 commissioning | Machine experts |') if ts[:4] == 'Tue.': print('| `00:00 - 07:00` | {{TopUp400}} | User Operation | OP shift crew |') print('| `07:00 - 09:00` | {{No_Light}} | Operator training | {{Felix}} and OP shift crew |') print('| `09:00 - 24:00` | {{No_Light}} | Machine development | Machine experts |') elif ts[:4] == 'Wed.': print('| `00:00 - 06:00` | {{No_Light}} | Machine development | Machine experts |') print('| `06:00 - 07:00` | {{Unstable}} | Machine startup | OP shift crew |') print('| `07:00 - 15:00` | {{TopUp400}} | Beamline development | OP shift crew |') print('| `15:00 - 24:00` | {{TopUp400}} | User Operation | OP shift crew |') else: # print('| `00:00 - 24:00` | {{TopUp400}} | Beamline development | OP shift crew |') print('| `00:00 - 24:00` | {{TopUp400}} | User Operation | OP shift crew |') print()