Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -185,7 +185,6 @@ def _build_product(blob: Dict[str, Any], currency: str, logs: List[str]) -> Dict
|
|
| 185 |
|
| 186 |
|
| 187 |
def _pick_shop_id(shops_resp: Any) -> str:
|
| 188 |
-
# Normalize the list from whatever wrapper Printify returns
|
| 189 |
if isinstance(shops_resp, list):
|
| 190 |
items = shops_resp
|
| 191 |
elif isinstance(shops_resp, dict):
|
|
@@ -196,23 +195,21 @@ def _pick_shop_id(shops_resp: Any) -> str:
|
|
| 196 |
if not isinstance(items, list) or not items:
|
| 197 |
raise RuntimeError("No shops found on /v1/shops.json for this token.")
|
| 198 |
|
| 199 |
-
#
|
| 200 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
|
| 202 |
for s in items:
|
| 203 |
if not isinstance(s, dict):
|
| 204 |
continue
|
| 205 |
-
title = s.get("title") or s.get("name")
|
| 206 |
-
if title
|
| 207 |
return str(s["id"])
|
| 208 |
|
| 209 |
-
|
| 210 |
-
for s in items:
|
| 211 |
-
if isinstance(s, dict) and s.get("id"):
|
| 212 |
-
return str(s["id"])
|
| 213 |
-
|
| 214 |
-
raise RuntimeError("Could not pick a shop id from response.")
|
| 215 |
-
|
| 216 |
|
| 217 |
def _upload_grid_from_file(logs: List[str]) -> Dict[str, Any]:
|
| 218 |
path = os.path.join(os.getcwd(), GRID_FILENAME)
|
|
|
|
| 185 |
|
| 186 |
|
| 187 |
def _pick_shop_id(shops_resp: Any) -> str:
|
|
|
|
| 188 |
if isinstance(shops_resp, list):
|
| 189 |
items = shops_resp
|
| 190 |
elif isinstance(shops_resp, dict):
|
|
|
|
| 195 |
if not isinstance(items, list) or not items:
|
| 196 |
raise RuntimeError("No shops found on /v1/shops.json for this token.")
|
| 197 |
|
| 198 |
+
# Hard override wins (set this in HF Secrets)
|
| 199 |
+
forced = os.environ.get("PRINTIFY_SHOP_ID")
|
| 200 |
+
if forced:
|
| 201 |
+
return str(forced)
|
| 202 |
+
|
| 203 |
+
preferred_name = os.environ.get("PRINTIFY_SHOP_NAME", "Atheria").strip().lower()
|
| 204 |
|
| 205 |
for s in items:
|
| 206 |
if not isinstance(s, dict):
|
| 207 |
continue
|
| 208 |
+
title = (s.get("title") or s.get("name") or "").strip().lower()
|
| 209 |
+
if title == preferred_name:
|
| 210 |
return str(s["id"])
|
| 211 |
|
| 212 |
+
raise RuntimeError(f"Preferred shop '{preferred_name}' not found; refusing to fallback.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 213 |
|
| 214 |
def _upload_grid_from_file(logs: List[str]) -> Dict[str, Any]:
|
| 215 |
path = os.path.join(os.getcwd(), GRID_FILENAME)
|