|
|
|
@ -19,34 +19,36 @@ def input_all_shifts_for_month(): |
|
|
|
today = datetime.date.today() |
|
|
|
max_day = cal_module.monthrange(today.year, today.month) |
|
|
|
start = datetime.date(today.year, today.month, 1) |
|
|
|
end = datetime.date(today.year, today.month, max_day[1]) |
|
|
|
read_from = datetime.datetime.combine( |
|
|
|
start, datetime.time(0, 0, 0, 0), datetime.timezone.utc |
|
|
|
end = datetime.date(today.year, today.month, max_day[1]) + datetime.timedelta( |
|
|
|
days=1 |
|
|
|
) |
|
|
|
|
|
|
|
start_dt = datetime.datetime.combine( |
|
|
|
start, datetime.time(0, 0, 0, 0), datetime.timezone.utc |
|
|
|
) |
|
|
|
end_dt = datetime.datetime.combine( |
|
|
|
end + datetime.timedelta(days=1), |
|
|
|
end, |
|
|
|
datetime.time(0, 0, 0, 0), |
|
|
|
datetime.timezone.utc, |
|
|
|
) |
|
|
|
for event in calendar.get_events(start_dt, end_dt): |
|
|
|
if event.end > read_from: |
|
|
|
read_from = event.end |
|
|
|
panera_session = login( |
|
|
|
config["credentials"]["username"], config["credentials"]["password"] |
|
|
|
) |
|
|
|
shifts_info = get_shifts_between( |
|
|
|
panera_session, |
|
|
|
datetime.date(read_from.year, read_from.month, read_from.day), |
|
|
|
start, |
|
|
|
end, |
|
|
|
) |
|
|
|
timezone = shifts_info["data"]["timezone"] |
|
|
|
cafe_info = shifts_info["data"]["currentShifts"]["cafe"][0] |
|
|
|
recorded_shifts = list(calendar.get_events(start_dt, end_dt)) |
|
|
|
for shift in shifts_info["data"]["currentShifts"]["shifts"]: |
|
|
|
s = Shift.from_dict(shift, cafe_info, timezone) |
|
|
|
if s.start > read_from: |
|
|
|
conflicts = any( |
|
|
|
s.start <= event.end and s.end >= event.start for event in recorded_shifts |
|
|
|
) |
|
|
|
if not conflicts: |
|
|
|
print(f"added: {s.start}-{s.end}") |
|
|
|
e = s.to_Event() |
|
|
|
calendar.update_or_add_event(e) |
|
|
|
|
|
|
|
|