|
@@ -1,3 +1,4 @@
|
|
|
|
|
+import logging
|
|
|
import os
|
|
import os
|
|
|
import subprocess
|
|
import subprocess
|
|
|
import sys
|
|
import sys
|
|
@@ -6,6 +7,8 @@ from pathlib import Path
|
|
|
|
|
|
|
|
from room_cal._utils import get_config
|
|
from room_cal._utils import get_config
|
|
|
|
|
|
|
|
|
|
+_log = logging.getLogger(__name__)
|
|
|
|
|
+
|
|
|
|
|
|
|
|
def _data_home() -> Path:
|
|
def _data_home() -> Path:
|
|
|
override = os.environ.get('ROOM_CAL_DATA_HOME')
|
|
override = os.environ.get('ROOM_CAL_DATA_HOME')
|
|
@@ -42,46 +45,58 @@ _booking_lock = threading.Lock()
|
|
|
def refresh_booking_cookies() -> None:
|
|
def refresh_booking_cookies() -> None:
|
|
|
ts_dir = _ts_dir()
|
|
ts_dir = _ts_dir()
|
|
|
_ensure_installed(ts_dir)
|
|
_ensure_installed(ts_dir)
|
|
|
|
|
+ _log.info('booking: starting credential refresh')
|
|
|
with _booking_lock:
|
|
with _booking_lock:
|
|
|
try:
|
|
try:
|
|
|
subprocess.run(['npm', 'run', 'refresh-booking'], cwd=ts_dir, env=_npm_env(), check=True)
|
|
subprocess.run(['npm', 'run', 'refresh-booking'], cwd=ts_dir, env=_npm_env(), check=True)
|
|
|
except subprocess.CalledProcessError as e:
|
|
except subprocess.CalledProcessError as e:
|
|
|
|
|
+ _log.error('booking: credential refresh failed (exit %d)', e.returncode)
|
|
|
from .types import ServiceAuthError
|
|
from .types import ServiceAuthError
|
|
|
raise ServiceAuthError(f'Booking.com credential refresh failed (exit {e.returncode})') from None
|
|
raise ServiceAuthError(f'Booking.com credential refresh failed (exit {e.returncode})') from None
|
|
|
|
|
+ _log.info('booking: credential refresh complete')
|
|
|
|
|
|
|
|
|
|
|
|
|
def refresh_airbnb_cookies() -> None:
|
|
def refresh_airbnb_cookies() -> None:
|
|
|
ts_dir = _ts_dir()
|
|
ts_dir = _ts_dir()
|
|
|
_ensure_installed(ts_dir)
|
|
_ensure_installed(ts_dir)
|
|
|
|
|
+ _log.info('airbnb: starting credential refresh')
|
|
|
env = _npm_env()
|
|
env = _npm_env()
|
|
|
env['HEADLESS'] = '1'
|
|
env['HEADLESS'] = '1'
|
|
|
try:
|
|
try:
|
|
|
subprocess.run(['npm', 'run', 'refresh-airbnb'], cwd=ts_dir, env=env, check=True)
|
|
subprocess.run(['npm', 'run', 'refresh-airbnb'], cwd=ts_dir, env=env, check=True)
|
|
|
except subprocess.CalledProcessError as e:
|
|
except subprocess.CalledProcessError as e:
|
|
|
|
|
+ _log.error('airbnb: credential refresh failed (exit %d)', e.returncode)
|
|
|
from .types import ServiceAuthError
|
|
from .types import ServiceAuthError
|
|
|
raise ServiceAuthError(f'Airbnb session expired — re-run without HEADLESS to re-authenticate (exit {e.returncode})') from None
|
|
raise ServiceAuthError(f'Airbnb session expired — re-run without HEADLESS to re-authenticate (exit {e.returncode})') from None
|
|
|
|
|
+ _log.info('airbnb: credential refresh complete')
|
|
|
|
|
|
|
|
|
|
|
|
|
def refresh_homestay_cookies() -> None:
|
|
def refresh_homestay_cookies() -> None:
|
|
|
ts_dir = _ts_dir()
|
|
ts_dir = _ts_dir()
|
|
|
_ensure_installed(ts_dir)
|
|
_ensure_installed(ts_dir)
|
|
|
|
|
+ _log.info('homestay: starting credential refresh')
|
|
|
env = _npm_env()
|
|
env = _npm_env()
|
|
|
try:
|
|
try:
|
|
|
subprocess.run(['npm', 'run', 'refresh-homestay'], cwd=ts_dir, env=env, check=True)
|
|
subprocess.run(['npm', 'run', 'refresh-homestay'], cwd=ts_dir, env=env, check=True)
|
|
|
except subprocess.CalledProcessError as e:
|
|
except subprocess.CalledProcessError as e:
|
|
|
|
|
+ _log.error('homestay: credential refresh failed (exit %d)', e.returncode)
|
|
|
from .types import ServiceAuthError
|
|
from .types import ServiceAuthError
|
|
|
raise ServiceAuthError(f'Homestay session expired — re-run without HEADLESS to re-authenticate (exit {e.returncode})') from None
|
|
raise ServiceAuthError(f'Homestay session expired — re-run without HEADLESS to re-authenticate (exit {e.returncode})') from None
|
|
|
|
|
+ _log.info('homestay: credential refresh complete')
|
|
|
|
|
|
|
|
|
|
|
|
|
def trigger_booking_chat_auth() -> None:
|
|
def trigger_booking_chat_auth() -> None:
|
|
|
"""Run booking-2fa; raises ServiceAuthError on failure. Safe to call from within the server."""
|
|
"""Run booking-2fa; raises ServiceAuthError on failure. Safe to call from within the server."""
|
|
|
ts_dir = _ts_dir()
|
|
ts_dir = _ts_dir()
|
|
|
_ensure_installed(ts_dir)
|
|
_ensure_installed(ts_dir)
|
|
|
|
|
+ _log.info('booking: starting standalone messaging 2FA prime')
|
|
|
with _booking_lock:
|
|
with _booking_lock:
|
|
|
result = subprocess.run(['npm', 'run', 'booking-2fa'], cwd=ts_dir, env=_npm_env())
|
|
result = subprocess.run(['npm', 'run', 'booking-2fa'], cwd=ts_dir, env=_npm_env())
|
|
|
if result.returncode != 0:
|
|
if result.returncode != 0:
|
|
|
|
|
+ _log.error('booking: booking-2fa failed (exit %d)', result.returncode)
|
|
|
from .types import ServiceAuthError
|
|
from .types import ServiceAuthError
|
|
|
raise ServiceAuthError(f'booking-2fa failed (exit {result.returncode}) — SMS gateway may not be configured')
|
|
raise ServiceAuthError(f'booking-2fa failed (exit {result.returncode}) — SMS gateway may not be configured')
|
|
|
|
|
+ _log.info('booking: messaging 2FA prime complete')
|
|
|
|
|
|
|
|
|
|
|
|
|
def _trigger_booking_chat_auth_cli() -> None:
|
|
def _trigger_booking_chat_auth_cli() -> None:
|