|
@@ -1,9 +1,9 @@
|
|
|
#!/usr/bin/env python3
|
|
#!/usr/bin/env python3
|
|
|
-"""Patch wifi_key and/or door_code on a reservation that contains a given date.
|
|
|
|
|
|
|
+"""Patch wifi_key, wifi_ssid, and/or door_code on a reservation that contains a given date.
|
|
|
|
|
|
|
|
Usage:
|
|
Usage:
|
|
|
uv run python3 scripts/patch_reservation_codes.py 2026-07-05 --wifi stone-angel-market --door 0472
|
|
uv run python3 scripts/patch_reservation_codes.py 2026-07-05 --wifi stone-angel-market --door 0472
|
|
|
- uv run python3 scripts/patch_reservation_codes.py 2026-07-05 --wifi new-word-combo
|
|
|
|
|
|
|
+ uv run python3 scripts/patch_reservation_codes.py 2026-07-05 --wifi new-word-combo --ssid MyNetwork
|
|
|
uv run python3 scripts/patch_reservation_codes.py 2026-07-05 --door 1234
|
|
uv run python3 scripts/patch_reservation_codes.py 2026-07-05 --door 1234
|
|
|
"""
|
|
"""
|
|
|
import argparse
|
|
import argparse
|
|
@@ -18,18 +18,19 @@ from room_cal._utils import safe_json_loads, filter_events, service_name
|
|
|
_PREFIX = 'Guest: '
|
|
_PREFIX = 'Guest: '
|
|
|
|
|
|
|
|
|
|
|
|
|
-def _build_description(xd: dict, wk: str, dc: str) -> str:
|
|
|
|
|
|
|
+def _build_description(xd: dict, wk: str, ws: str | None, dc: str) -> str:
|
|
|
svc = xd.get('service', '')
|
|
svc = xd.get('service', '')
|
|
|
|
|
+ wifi_line = f"WiFi: {ws} / {wk}" if ws else f"WiFi: {wk}"
|
|
|
return (
|
|
return (
|
|
|
f"Name: {xd.get('guest_name', '')}\n"
|
|
f"Name: {xd.get('guest_name', '')}\n"
|
|
|
f"Service: {service_name(svc)}\n"
|
|
f"Service: {service_name(svc)}\n"
|
|
|
f"Reservation ID: {xd.get('reservation_id', '')}\n"
|
|
f"Reservation ID: {xd.get('reservation_id', '')}\n"
|
|
|
f"Door: {dc}\n"
|
|
f"Door: {dc}\n"
|
|
|
- f"WiFi: {wk}"
|
|
|
|
|
|
|
+ f"{wifi_line}"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
-async def patch(target: date, new_wifi: str | None, new_door: str | None, calendar_name: str) -> None:
|
|
|
|
|
|
|
+async def patch(target: date, new_wifi: str | None, new_ssid: str | None, new_door: str | None, calendar_name: str) -> None:
|
|
|
cal = Calendar(calendar_name)
|
|
cal = Calendar(calendar_name)
|
|
|
events = await cal.fetch_date_range(target, target)
|
|
events = await cal.fetch_date_range(target, target)
|
|
|
reservations = filter_events(events, _PREFIX, all_day=False)
|
|
reservations = filter_events(events, _PREFIX, all_day=False)
|
|
@@ -47,14 +48,18 @@ async def patch(target: date, new_wifi: str | None, new_door: str | None, calend
|
|
|
xd = safe_json_loads(event['x_data']) or {}
|
|
xd = safe_json_loads(event['x_data']) or {}
|
|
|
|
|
|
|
|
old_wifi = xd.get('wifi_key', '(none)')
|
|
old_wifi = xd.get('wifi_key', '(none)')
|
|
|
|
|
+ old_ssid = xd.get('wifi_ssid')
|
|
|
old_door = xd.get('door_code', '(none)')
|
|
old_door = xd.get('door_code', '(none)')
|
|
|
|
|
|
|
|
wk = new_wifi if new_wifi is not None else old_wifi
|
|
wk = new_wifi if new_wifi is not None else old_wifi
|
|
|
|
|
+ ws = new_ssid if new_ssid is not None else old_ssid
|
|
|
dc = new_door if new_door is not None else old_door
|
|
dc = new_door if new_door is not None else old_door
|
|
|
|
|
|
|
|
print(f"Reservation: {event['title']} ({event['start'].date()} – {event['end'].date()})")
|
|
print(f"Reservation: {event['title']} ({event['start'].date()} – {event['end'].date()})")
|
|
|
if new_wifi is not None:
|
|
if new_wifi is not None:
|
|
|
print(f" wifi_key: {old_wifi!r} → {wk!r}")
|
|
print(f" wifi_key: {old_wifi!r} → {wk!r}")
|
|
|
|
|
+ if new_ssid is not None:
|
|
|
|
|
+ print(f" wifi_ssid: {old_ssid!r} → {ws!r}")
|
|
|
if new_door is not None:
|
|
if new_door is not None:
|
|
|
print(f" door_code: {old_door!r} → {dc!r}")
|
|
print(f" door_code: {old_door!r} → {dc!r}")
|
|
|
|
|
|
|
@@ -64,9 +69,10 @@ async def patch(target: date, new_wifi: str | None, new_door: str | None, calend
|
|
|
return
|
|
return
|
|
|
|
|
|
|
|
xd['wifi_key'] = wk
|
|
xd['wifi_key'] = wk
|
|
|
|
|
+ xd['wifi_ssid'] = ws
|
|
|
xd['door_code'] = dc
|
|
xd['door_code'] = dc
|
|
|
new_x_data = json.dumps(xd)
|
|
new_x_data = json.dumps(xd)
|
|
|
- new_description = _build_description(xd, wk, dc)
|
|
|
|
|
|
|
+ new_description = _build_description(xd, wk, ws, dc)
|
|
|
|
|
|
|
|
await cal.update_event(event, description=new_description, x_data=new_x_data)
|
|
await cal.update_event(event, description=new_description, x_data=new_x_data)
|
|
|
print("Updated.")
|
|
print("Updated.")
|
|
@@ -76,14 +82,15 @@ def main():
|
|
|
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
|
parser.add_argument('date', type=date.fromisoformat, help='Any date within the reservation (YYYY-MM-DD)')
|
|
parser.add_argument('date', type=date.fromisoformat, help='Any date within the reservation (YYYY-MM-DD)')
|
|
|
parser.add_argument('--wifi', metavar='WIFI_KEY', help='New wifi_key string')
|
|
parser.add_argument('--wifi', metavar='WIFI_KEY', help='New wifi_key string')
|
|
|
|
|
+ parser.add_argument('--ssid', metavar='WIFI_SSID', help='New wifi_ssid string')
|
|
|
parser.add_argument('--door', metavar='DOOR_CODE', help='New door_code string')
|
|
parser.add_argument('--door', metavar='DOOR_CODE', help='New door_code string')
|
|
|
parser.add_argument('--calendar', default=DEFAULT_CALENDAR_NAME, help=f'Calendar name (default: {DEFAULT_CALENDAR_NAME})')
|
|
parser.add_argument('--calendar', default=DEFAULT_CALENDAR_NAME, help=f'Calendar name (default: {DEFAULT_CALENDAR_NAME})')
|
|
|
args = parser.parse_args()
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
- if args.wifi is None and args.door is None:
|
|
|
|
|
- parser.error('Provide at least one of --wifi or --door')
|
|
|
|
|
|
|
+ if args.wifi is None and args.ssid is None and args.door is None:
|
|
|
|
|
+ parser.error('Provide at least one of --wifi, --ssid, or --door')
|
|
|
|
|
|
|
|
- asyncio.run(patch(args.date, args.wifi, args.door, args.calendar))
|
|
|
|
|
|
|
+ asyncio.run(patch(args.date, args.wifi, args.ssid, args.door, args.calendar))
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
if __name__ == '__main__':
|