72 lines
2.0 KiB
Python
72 lines
2.0 KiB
Python
"""Fetcher: pull one or more products from kikocosmetics.com product URLs.
|
|
|
|
Config JSON in admin Fetch panel:
|
|
{
|
|
"urls": [
|
|
"https://www.kikocosmetics.com/en-gb/p/love-fusion-24h-moisture-radiant-foundation-1-52012/"
|
|
],
|
|
"market": "en-gb"
|
|
}
|
|
|
|
Or a single "url" / "query" for one product.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from kiko_enrich import fetch_kiko_product
|
|
|
|
NAME = "KIKO Cosmetics (official site)"
|
|
DESCRIPTION = (
|
|
"Fetch product description, details table and color variants from kikocosmetics.com. "
|
|
"Upserts by sku/name — does not invent duplicate families."
|
|
)
|
|
|
|
|
|
def fetch_products(config: dict):
|
|
config = config or {}
|
|
market = config.get("market") or "en-gb"
|
|
urls = config.get("urls")
|
|
rows = []
|
|
if isinstance(urls, list) and urls:
|
|
for url in urls:
|
|
if not url:
|
|
continue
|
|
rows.append(fetch_kiko_product(url=str(url), market=market))
|
|
return rows
|
|
product = fetch_kiko_product(
|
|
url=config.get("url"),
|
|
query=config.get("query") or config.get("name"),
|
|
market=market,
|
|
)
|
|
return [product]
|
|
|
|
|
|
def sync_stocks(config: dict, products: list):
|
|
"""Refresh sellable flags from KIKO for products that already have sourceUrl/sku."""
|
|
config = config or {}
|
|
market = config.get("market") or "en-gb"
|
|
out = []
|
|
for p in products or []:
|
|
url = p.get("sourceUrl")
|
|
sku = p.get("sku")
|
|
if not url and not sku:
|
|
continue
|
|
try:
|
|
fetched = fetch_kiko_product(
|
|
url=url,
|
|
query=p.get("name") if not url else None,
|
|
market=market,
|
|
)
|
|
except Exception:
|
|
continue
|
|
out.append(
|
|
{
|
|
"id": p.get("id"),
|
|
"sku": fetched.get("sku") or sku,
|
|
"external_id": fetched.get("externalId") or p.get("externalId"),
|
|
"slug": p.get("slug"),
|
|
"stock": int(fetched.get("stock") or 0),
|
|
}
|
|
)
|
|
return out
|