feat: auto update
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
from config import BASE_URL
|
||||
|
||||
import json
|
||||
import xml.etree.ElementTree as ET
|
||||
from typing import List, Dict
|
||||
@@ -9,8 +11,9 @@ class RobotVacuumYMLGenerator:
|
||||
def __init__(
|
||||
self,
|
||||
shop_name: str = "Euro Electronics",
|
||||
base_url: str = "https://mario.mrakells.pp.ua",
|
||||
base_url: str = BASE_URL,
|
||||
use_original_urls: bool = False,
|
||||
categories_data: List[Dict] = None,
|
||||
):
|
||||
"""
|
||||
Initialize YML feed generator
|
||||
@@ -29,6 +32,7 @@ class RobotVacuumYMLGenerator:
|
||||
|
||||
self.categories = ET.SubElement(self.shop, "categories")
|
||||
self.offers = ET.SubElement(self.shop, "offers")
|
||||
self.categories_data = categories_data or []
|
||||
|
||||
def add_category(self, category_id: str, category_name: str, parent_id: str = None):
|
||||
"""
|
||||
@@ -110,13 +114,17 @@ class RobotVacuumYMLGenerator:
|
||||
:param product: Product dictionary from JSON
|
||||
"""
|
||||
|
||||
in_stock = product.get('in_stock', False)
|
||||
in_stock = product.get("in_stock", False)
|
||||
|
||||
offer = ET.SubElement(self.offers, 'offer', {
|
||||
'id': str(product['plu']),
|
||||
'available': 'true' if in_stock else 'false',
|
||||
'in_stock': 'true' if in_stock else 'false'
|
||||
})
|
||||
offer = ET.SubElement(
|
||||
self.offers,
|
||||
"offer",
|
||||
{
|
||||
"id": str(product["plu"]),
|
||||
"available": "true" if in_stock else "false",
|
||||
"in_stock": "true" if in_stock else "false",
|
||||
},
|
||||
)
|
||||
|
||||
# Clean product name before adding to feed
|
||||
cleaned_name = self.clean_product_name(product["name"])
|
||||
@@ -134,6 +142,28 @@ class RobotVacuumYMLGenerator:
|
||||
product["portal_category_id"]
|
||||
) # ОБОВ'ЯЗКОВО
|
||||
|
||||
# Додаємо keywords із назви категорії
|
||||
category_name = ""
|
||||
local_category_id = product.get("local_category_id")
|
||||
if self.categories_data:
|
||||
match = next(
|
||||
(
|
||||
c
|
||||
for c in self.categories_data
|
||||
if str(c["id"]) == str(local_category_id)
|
||||
),
|
||||
None,
|
||||
)
|
||||
if match:
|
||||
category_name = match["name"]
|
||||
|
||||
keywords = product.get("keywords", "")
|
||||
combined_keywords = category_name
|
||||
if keywords:
|
||||
combined_keywords += f", {keywords}"
|
||||
|
||||
ET.SubElement(offer, "keywords").text = combined_keywords
|
||||
|
||||
# Description with images
|
||||
if "description" in product:
|
||||
description_html = "<div>"
|
||||
|
||||
Reference in New Issue
Block a user