|
@@ -1,3 +1,4 @@
|
|
|
|
|
+import asyncio
|
|
|
import logging
|
|
import logging
|
|
|
import os
|
|
import os
|
|
|
import subprocess
|
|
import subprocess
|
|
@@ -37,12 +38,24 @@ def _ensure_installed(ts_dir: Path) -> None:
|
|
|
print()
|
|
print()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+def _assert_not_async(fn_name: str) -> None:
|
|
|
|
|
+ try:
|
|
|
|
|
+ asyncio.get_running_loop()
|
|
|
|
|
+ except RuntimeError:
|
|
|
|
|
+ return
|
|
|
|
|
+ raise RuntimeError(
|
|
|
|
|
+ f'{fn_name}() called from an async context — '
|
|
|
|
|
+ 'use run_in_executor to avoid blocking the event loop'
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
# One SMS code is valid at a time and Booking.com rate-limits sends regardless of how often we ask,
|
|
# One SMS code is valid at a time and Booking.com rate-limits sends regardless of how often we ask,
|
|
|
# so there is no benefit to concurrent booking browser operations — serialize them all.
|
|
# so there is no benefit to concurrent booking browser operations — serialize them all.
|
|
|
_booking_lock = threading.Lock()
|
|
_booking_lock = threading.Lock()
|
|
|
|
|
|
|
|
|
|
|
|
|
def refresh_booking_cookies() -> None:
|
|
def refresh_booking_cookies() -> None:
|
|
|
|
|
+ _assert_not_async('refresh_booking_cookies')
|
|
|
ts_dir = _ts_dir()
|
|
ts_dir = _ts_dir()
|
|
|
_ensure_installed(ts_dir)
|
|
_ensure_installed(ts_dir)
|
|
|
_log.info('booking: starting credential refresh')
|
|
_log.info('booking: starting credential refresh')
|
|
@@ -57,6 +70,7 @@ def refresh_booking_cookies() -> None:
|
|
|
|
|
|
|
|
|
|
|
|
|
def refresh_airbnb_cookies() -> None:
|
|
def refresh_airbnb_cookies() -> None:
|
|
|
|
|
+ _assert_not_async('refresh_airbnb_cookies')
|
|
|
ts_dir = _ts_dir()
|
|
ts_dir = _ts_dir()
|
|
|
_ensure_installed(ts_dir)
|
|
_ensure_installed(ts_dir)
|
|
|
_log.info('airbnb: starting credential refresh')
|
|
_log.info('airbnb: starting credential refresh')
|