concurrency-fix #15
@@ -44,7 +44,7 @@ from .alpinebits_server import (
|
||||
)
|
||||
from .auth import validate_api_key
|
||||
from .config_loader import load_config, get_username_for_hotel
|
||||
from .const import CONF_GOOGLE_ACCOUNT, CONF_HOTEL_ID, CONF_META_ACCOUNT, HttpStatusCode, WebhookStatus
|
||||
from .const import HttpStatusCode, WebhookStatus
|
||||
from .conversion_service import ConversionService
|
||||
from .csv_import import CSVImporter
|
||||
from .db import Customer as DBCustomer
|
||||
@@ -79,45 +79,6 @@ security_bearer = HTTPBearer()
|
||||
TOKEN_LOG_LENGTH = 10
|
||||
|
||||
|
||||
def get_advertising_account_ids(
|
||||
config: dict[str, Any], hotel_code: str, fbclid: str | None, gclid: str | None
|
||||
) -> tuple[str | None, str | None]:
|
||||
"""Get advertising account IDs based on hotel config and click IDs.
|
||||
|
||||
Args:
|
||||
config: Application configuration dict
|
||||
hotel_code: Hotel identifier to look up in config
|
||||
fbclid: Facebook click ID (if present, meta_account_id will be returned)
|
||||
gclid: Google click ID (if present, google_account_id will be returned)
|
||||
|
||||
Returns:
|
||||
Tuple of (meta_account_id, google_account_id) based on conditional logic:
|
||||
- meta_account_id is set only if fbclid is present AND hotel has
|
||||
meta_account configured
|
||||
- google_account_id is set only if gclid is present AND hotel has
|
||||
google_account configured
|
||||
|
||||
"""
|
||||
meta_account_id = None
|
||||
google_account_id = None
|
||||
|
||||
# Look up hotel in config
|
||||
alpine_bits_auth = config.get("alpine_bits_auth", [])
|
||||
for hotel in alpine_bits_auth:
|
||||
if hotel.get(CONF_HOTEL_ID) == hotel_code:
|
||||
# Conditionally set meta_account_id if fbclid is present
|
||||
if fbclid:
|
||||
meta_account_id = hotel.get(CONF_META_ACCOUNT)
|
||||
|
||||
# Conditionally set google_account_id if gclid is present
|
||||
if gclid:
|
||||
google_account_id = hotel.get(CONF_GOOGLE_ACCOUNT)
|
||||
|
||||
break
|
||||
|
||||
return meta_account_id, google_account_id
|
||||
|
||||
|
||||
# Pydantic models for language detection
|
||||
class LanguageDetectionRequest(BaseModel):
|
||||
text: str
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from annotatedyaml.loader import Secrets
|
||||
from annotatedyaml.loader import load_yaml as load_annotated_yaml
|
||||
@@ -334,3 +335,42 @@ def load_config():
|
||||
def get_username_for_hotel(config: dict, hotel_code: str) -> str:
|
||||
"""Get the username associated with a hotel_code from config."""
|
||||
return next(h.get("username") for h in config.get("alpine_bits_auth", []) if h.get("hotel_id") == hotel_code)
|
||||
|
||||
|
||||
def get_advertising_account_ids(
|
||||
config: dict[str, Any], hotel_code: str, fbclid: str | None, gclid: str | None
|
||||
) -> tuple[str | None, str | None]:
|
||||
"""Get advertising account IDs based on hotel config and click IDs.
|
||||
|
||||
Args:
|
||||
config: Application configuration dict
|
||||
hotel_code: Hotel identifier to look up in config
|
||||
fbclid: Facebook click ID (if present, meta_account_id will be returned)
|
||||
gclid: Google click ID (if present, google_account_id will be returned)
|
||||
|
||||
Returns:
|
||||
Tuple of (meta_account_id, google_account_id) based on conditional logic:
|
||||
- meta_account_id is set only if fbclid is present AND hotel has
|
||||
meta_account configured
|
||||
- google_account_id is set only if gclid is present AND hotel has
|
||||
google_account configured
|
||||
|
||||
"""
|
||||
meta_account_id = None
|
||||
google_account_id = None
|
||||
|
||||
# Look up hotel in config
|
||||
alpine_bits_auth = config.get("alpine_bits_auth", [])
|
||||
for hotel in alpine_bits_auth:
|
||||
if hotel.get(CONF_HOTEL_ID) == hotel_code:
|
||||
# Conditionally set meta_account_id if fbclid is present
|
||||
if fbclid:
|
||||
meta_account_id = hotel.get(CONF_META_ACCOUNT)
|
||||
|
||||
# Conditionally set google_account_id if gclid is present
|
||||
if gclid:
|
||||
google_account_id = hotel.get(CONF_GOOGLE_ACCOUNT)
|
||||
|
||||
break
|
||||
|
||||
return meta_account_id, google_account_id
|
||||
|
||||
@@ -8,12 +8,14 @@ from typing import Any, Protocol
|
||||
from fastapi import HTTPException, Request
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from alpine_bits_python.api import _LOGGER, get_advertising_account_ids
|
||||
from alpine_bits_python.config_loader import get_advertising_account_ids
|
||||
from alpine_bits_python.auth import generate_unique_id
|
||||
from alpine_bits_python.customer_service import CustomerService
|
||||
from alpine_bits_python.reservation_service import ReservationService
|
||||
from alpine_bits_python.schemas import ReservationData
|
||||
|
||||
|
||||
|
||||
from .db import Hotel, WebhookRequest
|
||||
from .logging_config import get_logger
|
||||
|
||||
|
||||
Reference in New Issue
Block a user