Fix sites_list category field names — category_id/category_name, not site_category_*
The rates Newbook instance returns categories as category_id/category_name on each site; also skip inactive categories. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
69c9b16a2b
commit
4977768645
1 changed files with 6 additions and 3 deletions
|
|
@ -97,8 +97,9 @@ class NewbookRatesClient:
|
||||||
"""
|
"""
|
||||||
Fetch room categories by grouping the sites_list endpoint.
|
Fetch room categories by grouping the sites_list endpoint.
|
||||||
|
|
||||||
Each site includes site_category_id and site_category_name; categories
|
Each site carries its category as category_id/category_name; categories
|
||||||
are derived by grouping sites and counting rooms per category.
|
are derived by grouping sites and counting rooms per category.
|
||||||
|
Inactive categories (category_active = "0") are skipped.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
List of dicts with {category_id, category_name, room_count}
|
List of dicts with {category_id, category_name, room_count}
|
||||||
|
|
@ -114,12 +115,14 @@ class NewbookRatesClient:
|
||||||
|
|
||||||
categories: Dict[str, Dict] = {}
|
categories: Dict[str, Dict] = {}
|
||||||
for site in sites:
|
for site in sites:
|
||||||
cat_id = str(site.get("site_category_id") or "")
|
cat_id = str(site.get("category_id") or site.get("site_category_id") or "")
|
||||||
if not cat_id:
|
if not cat_id:
|
||||||
continue
|
continue
|
||||||
|
if str(site.get("category_active", "1")) == "0":
|
||||||
|
continue
|
||||||
entry = categories.setdefault(cat_id, {
|
entry = categories.setdefault(cat_id, {
|
||||||
"category_id": cat_id,
|
"category_id": cat_id,
|
||||||
"category_name": site.get("site_category_name") or f"Category {cat_id}",
|
"category_name": site.get("category_name") or site.get("site_category_name") or f"Category {cat_id}",
|
||||||
"room_count": 0,
|
"room_count": 0,
|
||||||
})
|
})
|
||||||
entry["room_count"] += 1
|
entry["room_count"] += 1
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue