|
|
@@ -1,8 +1,8 @@
|
|
|
from datetime import date
|
|
|
|
|
|
from room_cal.closed import Closed, ClosedData
|
|
|
-from room_cal.user_cal import UserCal, DEFAULT_CALENDAR_NAME as USER_CAL_DEFAULT
|
|
|
-from room_cal._utils import FetchResult, safe_json_loads, services as _services, event_dates, drop_stale_events
|
|
|
+from room_cal.user_cal import UserCal
|
|
|
+from room_cal._utils import FetchResult, get_config, safe_json_loads, services as _services, event_dates, drop_stale_events
|
|
|
|
|
|
ACTION_SPEC = ('fetch-user-cal', [])
|
|
|
|
|
|
@@ -23,7 +23,8 @@ async def fetch_user_cal(
|
|
|
user_cal = UserCal()
|
|
|
closed_cal = Closed()
|
|
|
all_services = sorted(_services())
|
|
|
- source = {'domain': _USER_CAL_SOURCE, 'name': 'User =>', 'id': USER_CAL_DEFAULT}
|
|
|
+ calendar_name = get_config().user_cal.calendar_name
|
|
|
+ source = {'domain': _USER_CAL_SOURCE, 'name': 'User =>', 'id': calendar_name}
|
|
|
|
|
|
blocked: set[date] = set()
|
|
|
for ev in await user_cal.find_closed(start_date, end_date):
|
|
|
@@ -36,10 +37,10 @@ async def fetch_user_cal(
|
|
|
for e in existing_closed:
|
|
|
xd = safe_json_loads(e.x_data)
|
|
|
src = (xd or {}).get('source', {})
|
|
|
- if src.get('domain') == _USER_CAL_SOURCE and src.get('id') == USER_CAL_DEFAULT:
|
|
|
+ if src.get('domain') == _USER_CAL_SOURCE and src.get('id') == calendar_name:
|
|
|
existing_covered.add(e.start.date())
|
|
|
|
|
|
- await drop_stale_events(existing_closed, blocked, domain=_USER_CAL_SOURCE, id_=USER_CAL_DEFAULT, cal=closed_cal)
|
|
|
+ await drop_stale_events(existing_closed, blocked, domain=_USER_CAL_SOURCE, id_=calendar_name, cal=closed_cal)
|
|
|
closed_by_date = {e.start.date(): e for e in existing_closed}
|
|
|
|
|
|
synced_closed: list[date] = []
|