Fix eBay HTML parser for post-2024 s-card layout, fix source field values

This commit is contained in:
Westech Admin
2026-05-19 16:33:17 +00:00
parent 750141827b
commit ebf907c9d5
5 changed files with 20 additions and 6 deletions
+18 -4
View File
@@ -35,7 +35,10 @@ def _get_oxylabs_creds():
user = password = ""
if settings:
user = settings.get("oxylabs_user") or ""
password = settings.get_password("oxylabs_password") or ""
try:
password = settings.get_password("oxylabs_password") or ""
except Exception:
pass
if not user:
user = frappe.conf.get("oxylabs_user", "")
if not password:
@@ -47,7 +50,10 @@ def _get_apify_token():
settings = _get_settings()
token = ""
if settings:
token = settings.get_password("apify_token") or ""
try:
token = settings.get_password("apify_token") or ""
except Exception:
pass
if not token:
token = frappe.conf.get("apify_token", "")
return token
@@ -292,7 +298,7 @@ def _parse_prices(items, manufacturer, model, source="oxylabs"):
"price_average": round(avg, 2),
"price_auction": round(median, 2),
"sample_count": len(prices),
"source": f"ebay_{source}",
"source": source or "unknown",
"scraped_at": now(),
}
@@ -311,9 +317,17 @@ def _upsert_system_pricing(manufacturer, model, pricing):
doc.manufacturer = manufacturer
doc.model = model
for key in ("price_high", "price_low", "price_average", "price_auction",
"sample_count", "source", "scraped_at"):
"sample_count", "scraped_at"):
if key in pricing:
setattr(doc, key, pricing[key])
# Fix source to match allowed values
if "source" in pricing:
raw_source = pricing["source"]
if raw_source.startswith("ebay_"):
raw_source = raw_source.replace("ebay_", "")
if raw_source not in ("oxylabs", "apify"):
raw_source = "unknown"
setattr(doc, "source", raw_source)
if doc.scraped_at:
scraped = frappe.utils.get_datetime(doc.scraped_at)
now = now_datetime()