|
@@ -4,7 +4,6 @@ from typing import TYPE_CHECKING
|
|
|
|
|
|
|
|
from room_cal.closed import Closed, ClosedData
|
|
from room_cal.closed import Closed, ClosedData
|
|
|
from room_cal.reservations import Reservation
|
|
from room_cal.reservations import Reservation
|
|
|
-from room_cal.user_cal import UserCal
|
|
|
|
|
from room_cal._utils import FetchResult, safe_json_loads, iter_dates, services as _services, service_name
|
|
from room_cal._utils import FetchResult, safe_json_loads, iter_dates, services as _services, service_name
|
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
if TYPE_CHECKING:
|
|
@@ -54,7 +53,6 @@ async def fetch_reservations(
|
|
|
api = _ServiceAPI()
|
|
api = _ServiceAPI()
|
|
|
res_cal = Reservation()
|
|
res_cal = Reservation()
|
|
|
closed = Closed()
|
|
closed = Closed()
|
|
|
- user_cal = UserCal()
|
|
|
|
|
all_service_keys = _services()
|
|
all_service_keys = _services()
|
|
|
|
|
|
|
|
existing_events = await res_cal.list(start_date, end_date)
|
|
existing_events = await res_cal.list(start_date, end_date)
|
|
@@ -135,23 +133,27 @@ async def fetch_reservations(
|
|
|
for day, data in closed_set_inputs
|
|
for day, data in closed_set_inputs
|
|
|
])
|
|
])
|
|
|
|
|
|
|
|
- ucal_events = await user_cal.find_services(start_date, end_date)
|
|
|
|
|
- ucal_by_id: dict[str, object] = {}
|
|
|
|
|
- for e in ucal_events:
|
|
|
|
|
- d = safe_json_loads(e.x_data)
|
|
|
|
|
- if d:
|
|
|
|
|
- rid = d.get('reservation_id')
|
|
|
|
|
- if rid:
|
|
|
|
|
- ucal_by_id[rid] = e
|
|
|
|
|
-
|
|
|
|
|
- await asyncio.gather(*[
|
|
|
|
|
- user_cal.delete(event)
|
|
|
|
|
- for rid, event in ucal_by_id.items()
|
|
|
|
|
- if rid not in service_ids
|
|
|
|
|
- ])
|
|
|
|
|
- await asyncio.gather(*[
|
|
|
|
|
- user_cal.set(r['service'], r['id'], r['start_date'], r['end_date'])
|
|
|
|
|
- for r in service_reservations
|
|
|
|
|
- ])
|
|
|
|
|
|
|
+ try:
|
|
|
|
|
+ from room_cal.user_cal import UserCal
|
|
|
|
|
+ user_cal = UserCal()
|
|
|
|
|
+ ucal_events = await user_cal.find_services(start_date, end_date)
|
|
|
|
|
+ ucal_by_id: dict[str, object] = {}
|
|
|
|
|
+ for e in ucal_events:
|
|
|
|
|
+ d = safe_json_loads(e.x_data)
|
|
|
|
|
+ if d:
|
|
|
|
|
+ rid = d.get('reservation_id')
|
|
|
|
|
+ if rid:
|
|
|
|
|
+ ucal_by_id[rid] = e
|
|
|
|
|
+ await asyncio.gather(*[
|
|
|
|
|
+ user_cal.delete(event)
|
|
|
|
|
+ for rid, event in ucal_by_id.items()
|
|
|
|
|
+ if rid not in service_ids
|
|
|
|
|
+ ])
|
|
|
|
|
+ await asyncio.gather(*[
|
|
|
|
|
+ user_cal.set(r['service'], r['id'], r['start_date'], r['end_date'])
|
|
|
|
|
+ for r in service_reservations
|
|
|
|
|
+ ])
|
|
|
|
|
+ except ImportError:
|
|
|
|
|
+ pass
|
|
|
|
|
|
|
|
return FetchResult(data=synced, changed=changed)
|
|
return FetchResult(data=synced, changed=changed)
|