功能迭代
This commit is contained in:
1 parent
8e03c99cab
commit
9e87a4002a
23 files changed
+553
-38
No files matched your search
Binary file not shown.
|
After Width: | Height: | Size: 398 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 137 KiB |
@@ -0,0 +1,102 @@
|
||||
"""为三款产品准备无中文的产品图与英文规格图。"""
|
||||
|
||||
from pathlib import Path
|
||||
from PIL import Image, ImageDraw, ImageFont, ImageOps
|
||||
|
||||
|
||||
SOURCE_ROOT = Path(r"C:\Users\29506\Desktop\cy\鸿遇工贸\产品图片")
|
||||
OUTPUT_ROOT = Path(r"E:\work\shangyuan\shoplix\output\product-import")
|
||||
FONT_REGULAR = Path(r"C:\Windows\Fonts\arial.ttf")
|
||||
FONT_BOLD = Path(r"C:\Windows\Fonts\arialbd.ttf")
|
||||
|
||||
PRODUCTS = {
|
||||
"HY-001": {
|
||||
"folder": "Protective Cover Trimmer Head - White HY-001",
|
||||
"name": "Protective Cover Trimmer Head - White",
|
||||
"files": [
|
||||
"O1CN01D8S3e9G83iC2XrKe_!!2217056636432-0-cib.jpg_.webp",
|
||||
"O1CN01OEkLBL7Ic8J2R3rs_!!2217056636432-0-cib.jpg_.webp",
|
||||
"O1CN01spYFDTqxaDF2R3rs_!!2217056636432-0-cib.jpg_.webp",
|
||||
"O1CN01t8mmPN9FSiF2R3rs_!!2217056636432-0-cib.jpg_.webp",
|
||||
],
|
||||
"specs": [("Material", "Metal + aluminum"), ("Dimensions", "80.5 × 80.5 × 23 mm"),
|
||||
("Net weight", "200 g"), ("Application", "Grass trimming")],
|
||||
},
|
||||
"HY-012": {
|
||||
"folder": "Large Aluminum Cylinder Trimmer Head HY-012",
|
||||
"name": "Large Aluminum Cylinder Trimmer Head",
|
||||
"files": [
|
||||
"O1CN01TZ4um7NgP8B1chua_!!2217056636432-0-cib.jpg_.webp",
|
||||
"O1CN01vpinbZvGDlK1chua_!!2217056636432-0-cib.jpg_.webp",
|
||||
"O1CN01zCrsDO1J0OE1chua_!!2217056636432-0-cib.jpg_.webp",
|
||||
],
|
||||
"specs": [("Material", "Aluminum alloy"), ("Dimensions", "45 × 45 × 55 mm"),
|
||||
("Net weight", "400 g"), ("Application", "Grass trimming")],
|
||||
},
|
||||
"HY-032": {
|
||||
"folder": "European-Type Trimmer Head - Orange HY-032",
|
||||
"name": "European-Type Trimmer Head - Orange",
|
||||
"files": [
|
||||
"O1CN01unDmzQcaXFC2b8G8_!!2217056636432-0-cib.jpg_.webp",
|
||||
"O1CN01UyV2HS9YFAC2b8G8_!!2217056636432-0-cib.jpg_.webp",
|
||||
"O1CN01wsHSM4JvXdD2b8G8_!!2217056636432-0-cib.jpg_.webp",
|
||||
],
|
||||
"specs": [("Material", "Engineering plastic + metal"), ("Dimensions", "145 × 145 × 75 mm"),
|
||||
("Net weight", "485 g"), ("Application", "Grass trimming")],
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def font(size: int, bold: bool = False) -> ImageFont.FreeTypeFont:
|
||||
"""加载用于英文详情图的系统字体。"""
|
||||
return ImageFont.truetype(str(FONT_BOLD if bold else FONT_REGULAR), size)
|
||||
|
||||
|
||||
def save_clean_image(source: Path, target: Path) -> None:
|
||||
"""将无中文的原图统一转为高质量 JPEG。"""
|
||||
image = Image.open(source).convert("RGB")
|
||||
image.save(target, "JPEG", quality=92, optimize=True)
|
||||
|
||||
|
||||
def create_specification_card(model: str, config: dict, product_image: Path, target: Path) -> None:
|
||||
"""基于实拍图生成全英文规格详情图。"""
|
||||
canvas = Image.new("RGB", (1200, 1200), "#f5f7f6")
|
||||
draw = ImageDraw.Draw(canvas)
|
||||
draw.rectangle((0, 0, 1200, 165), fill="#176b5b")
|
||||
draw.text((70, 48), config["name"], font=font(44, True), fill="white")
|
||||
draw.text((72, 108), model, font=font(25), fill="#d7eee7")
|
||||
product = Image.open(product_image).convert("RGB")
|
||||
product = ImageOps.contain(product, (540, 650))
|
||||
x = 70 + (540 - product.width) // 2
|
||||
y = 230 + (650 - product.height) // 2
|
||||
canvas.paste(product, (x, y))
|
||||
draw.rounded_rectangle((660, 230, 1130, 910), radius=22, fill="white", outline="#dce4e1", width=2)
|
||||
draw.text((710, 282), "Product specifications", font=font(30, True), fill="#16221f")
|
||||
row_y = 370
|
||||
for label, value in config["specs"]:
|
||||
draw.text((710, row_y), label.upper(), font=font(17, True), fill="#71817c")
|
||||
draw.text((710, row_y + 34), value, font=font(25), fill="#17211f")
|
||||
draw.line((710, row_y + 86, 1080, row_y + 86), fill="#e5eae8", width=2)
|
||||
row_y += 125
|
||||
draw.text((70, 1030), "OEM & wholesale inquiries are welcome", font=font(30, True), fill="#176b5b")
|
||||
draw.text((70, 1082), "Confirm machine compatibility before ordering.", font=font(23), fill="#64736e")
|
||||
canvas.save(target, "JPEG", quality=93, optimize=True)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
"""输出三款产品的清洁图库和英文规格图。"""
|
||||
OUTPUT_ROOT.mkdir(parents=True, exist_ok=True)
|
||||
for model, config in PRODUCTS.items():
|
||||
product_dir = OUTPUT_ROOT / model
|
||||
product_dir.mkdir(parents=True, exist_ok=True)
|
||||
source_dir = SOURCE_ROOT / config["folder"]
|
||||
prepared = []
|
||||
for index, filename in enumerate(config["files"], start=1):
|
||||
target = product_dir / f"{model.lower()}-{index}.jpg"
|
||||
save_clean_image(source_dir / filename, target)
|
||||
prepared.append(target)
|
||||
create_specification_card(model, config, prepared[0], product_dir / f"{model.lower()}-specifications-en.jpg")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,120 @@
|
||||
"""上传三款产品图片,并更新英文详情与规格属性。"""
|
||||
|
||||
from pathlib import Path
|
||||
from html import escape
|
||||
import requests
|
||||
|
||||
|
||||
BASE_URL = "http://127.0.0.1:8081/api/admin/v1"
|
||||
SITE_CODE = "SIT0000000000001"
|
||||
IMAGE_ROOT = Path(r"E:\work\shangyuan\shoplix\output\product-import")
|
||||
|
||||
PRODUCT_DATA = {
|
||||
"HY-001": {
|
||||
"intro": "A durable protective-cover trimmer head supplied with replaceable nylon lines for efficient grass trimming and routine garden maintenance.",
|
||||
"features": ["Metal and aluminum construction", "Compact protective-cover design", "Replaceable nylon trimming lines", "Suitable for garden and landscape maintenance"],
|
||||
"specifications": [("General", "Material", "Metal + aluminum", ""), ("Dimensions", "Size", "80.5 × 80.5 × 23", "mm"), ("Dimensions", "Net weight", "200", "g"), ("Application", "Use", "Grass trimming", "")],
|
||||
},
|
||||
"HY-012": {
|
||||
"intro": "A heavy-duty aluminum cylinder trimmer head designed for reliable line feeding, quick line replacement and demanding garden-tool applications.",
|
||||
"features": ["Thickened aluminum-alloy housing", "Quick and convenient line replacement", "Multiple line outlets for efficient cutting", "OEM and wholesale supply available"],
|
||||
"specifications": [("General", "Material", "Aluminum alloy", ""), ("Dimensions", "Diameter", "45", "mm"), ("Dimensions", "Height", "55", "mm"), ("Dimensions", "Net weight", "400", "g"), ("Application", "Use", "Grass trimming", "")],
|
||||
},
|
||||
"HY-032": {
|
||||
"intro": "A European-style orange trimmer head combining a robust housing, practical line-feeding structure and broad compatibility for grass-cutting equipment.",
|
||||
"features": ["European-style trimmer-head design", "Engineering-plastic and metal construction", "Large 145 mm working diameter", "Suitable for garden and landscape maintenance"],
|
||||
"specifications": [("General", "Material", "Engineering plastic + metal", ""), ("Dimensions", "Length", "145", "mm"), ("Dimensions", "Width", "145", "mm"), ("Dimensions", "Height", "75", "mm"), ("Dimensions", "Net weight", "485", "g"), ("Application", "Use", "Grass trimming", "")],
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def login(session: requests.Session) -> None:
|
||||
"""登录运营后台并保持会话。"""
|
||||
response = session.post(f"{BASE_URL}/auth/login", json={"username": "admin", "password": "Shoplix@2026"}, timeout=30)
|
||||
response.raise_for_status()
|
||||
|
||||
|
||||
def find_product(session: requests.Session, model: str) -> dict:
|
||||
"""按型号查找产品并读取完整详情。"""
|
||||
response = session.post(f"{BASE_URL}/products/list", json={"siteCode": SITE_CODE}, timeout=30)
|
||||
response.raise_for_status()
|
||||
item = next((row for row in response.json().get("items", []) if row.get("model") == model), None)
|
||||
if item is None:
|
||||
raise RuntimeError(f"Product not found: {model}")
|
||||
detail = session.post(f"{BASE_URL}/products/detail", json={"siteCode": SITE_CODE, "productCode": item["productCode"]}, timeout=30)
|
||||
detail.raise_for_status()
|
||||
return detail.json()
|
||||
|
||||
|
||||
def find_existing_media(session: requests.Session, filename: str) -> dict | None:
|
||||
"""复用已经上传的同名素材,避免重复写入。"""
|
||||
response = session.post(f"{BASE_URL}/media/page", json={"siteCode": SITE_CODE, "mediaType": "IMAGE", "keyword": filename, "tagName": "", "pageNo": 1, "pageSize": 30}, timeout=30)
|
||||
response.raise_for_status()
|
||||
return next((item for item in response.json().get("items", []) if item.get("originalFileName") == filename), None)
|
||||
|
||||
|
||||
def upload_image(session: requests.Session, path: Path, model: str) -> dict:
|
||||
"""上传单张产品图并返回素材信息。"""
|
||||
existing = find_existing_media(session, path.name)
|
||||
if existing:
|
||||
return existing
|
||||
with path.open("rb") as file_handle:
|
||||
response = session.post(f"{BASE_URL}/media/upload", data={"siteCode": SITE_CODE, "altText": f"{model} product image"}, files={"file": (path.name, file_handle, "image/jpeg")}, timeout=120)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
|
||||
|
||||
def build_content(detail: dict, config: dict, media: list[dict]) -> str:
|
||||
"""生成包含英文卖点和实拍图的产品详情 HTML。"""
|
||||
name = escape(detail["productName"])
|
||||
features = "".join(f"<li>{escape(item)}</li>" for item in config["features"])
|
||||
image_blocks = "".join(
|
||||
f'<figure style="margin:24px 0;text-align:center"><img src="{escape(item["url"])}" alt="{name}" style="max-width:100%;height:auto" /></figure>'
|
||||
for item in media[1:3]
|
||||
)
|
||||
return (
|
||||
f"<h2>{name}</h2><p>{escape(config['intro'])}</p>"
|
||||
f"<h3>Key features</h3><ul>{features}</ul>{image_blocks}"
|
||||
"<h3>OEM & wholesale service</h3><p>Custom packaging, product configuration and bulk-order support are available. Please confirm machine compatibility before ordering.</p>"
|
||||
)
|
||||
|
||||
|
||||
def update_product(session: requests.Session, model: str, detail: dict, config: dict, media: list[dict]) -> None:
|
||||
"""保存产品多图、英文详情和英文规格属性。"""
|
||||
specifications = [
|
||||
{"groupName": group, "name": name, "value": value, "unit": unit, "sortNo": index}
|
||||
for index, (group, name, value, unit) in enumerate(config["specifications"], start=1)
|
||||
]
|
||||
attributes = [
|
||||
{"attributeCode": None, "attributeName": name, "value": f"{value}{(' ' + unit) if unit else ''}", "unit": unit, "sortNo": index}
|
||||
for index, (_, name, value, unit) in enumerate(config["specifications"], start=1)
|
||||
]
|
||||
request = {
|
||||
"productCode": detail["productCode"], "siteCode": SITE_CODE,
|
||||
"primaryCategoryCode": detail.get("primaryCategoryCode"), "productName": detail["productName"],
|
||||
"slug": detail["slug"], "model": detail.get("model"), "summary": config["intro"],
|
||||
"productContent": build_content(detail, config, media),
|
||||
"contentTemplateCode": detail.get("contentTemplateCode") or "", "templatePosition": detail.get("templatePosition") or "AFTER",
|
||||
"coverMediaCode": media[0]["mediaCode"],
|
||||
"images": [{"mediaCode": item["mediaCode"], "sortNo": index} for index, item in enumerate(media)],
|
||||
"featured": detail.get("featured", False), "inquiryEnabled": detail.get("inquiryEnabled", True),
|
||||
"sortNo": detail.get("sortNo", 0), "status": detail["status"],
|
||||
"specifications": specifications, "attributes": attributes,
|
||||
}
|
||||
response = session.post(f"{BASE_URL}/products/save", json=request, timeout=60)
|
||||
response.raise_for_status()
|
||||
|
||||
|
||||
def main() -> None:
|
||||
"""完成三款产品的素材上传和数据更新。"""
|
||||
with requests.Session() as session:
|
||||
login(session)
|
||||
for model, config in PRODUCT_DATA.items():
|
||||
detail = find_product(session, model)
|
||||
media = [upload_image(session, path, model) for path in sorted((IMAGE_ROOT / model).glob("*.jpg"))]
|
||||
update_product(session, model, detail, config, media)
|
||||
print(f"Updated {model}: {len(media)} images")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 211 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 121 KiB |
@@ -0,0 +1,58 @@
|
||||
1
|
||||
00:00:00,000 --> 00:00:04,840
|
||||
Welcome to Yongkang Hongyu Industry and Trade Co., Ltd.
|
||||
I am the company representative.
|
||||
|
||||
2
|
||||
00:00:04,840 --> 00:00:09,760
|
||||
We specialize in garden tools, trimmer line,
|
||||
trimmer heads and related accessories.
|
||||
|
||||
3
|
||||
00:00:09,760 --> 00:00:12,640
|
||||
Let me show you around our factory.
|
||||
|
||||
4
|
||||
00:00:12,640 --> 00:00:16,000
|
||||
Established in 2020, our factory
|
||||
has a team of 50 employees.
|
||||
|
||||
5
|
||||
00:00:16,000 --> 00:00:21,760
|
||||
Located in Gushan Town, Yongkang,
|
||||
our factory covers 3,800 square meters.
|
||||
|
||||
6
|
||||
00:00:21,760 --> 00:00:28,200
|
||||
Our modern facility produces trimmer heads
|
||||
and a wide range of garden tool accessories.
|
||||
|
||||
7
|
||||
00:00:28,280 --> 00:00:34,560
|
||||
With dedicated equipment and an R&D team, capacity reaches
|
||||
about 20,000 pieces per day and 6 million pieces per year.
|
||||
|
||||
8
|
||||
00:00:34,560 --> 00:00:40,400
|
||||
Our products are exported to Russia, Southeast Asia,
|
||||
Europe and other markets. OEM service is available.
|
||||
|
||||
9
|
||||
00:00:40,400 --> 00:00:45,400
|
||||
From incoming materials to final shipment,
|
||||
every stage is controlled for reliable quality.
|
||||
|
||||
10
|
||||
00:00:45,400 --> 00:00:49,440
|
||||
We provide one-stop ODM service,
|
||||
from product design and R&D to manufacturing.
|
||||
|
||||
11
|
||||
00:00:49,440 --> 00:00:56,400
|
||||
We also manufacture for established brands,
|
||||
earning strong recognition from industry buyers.
|
||||
|
||||
12
|
||||
00:00:56,440 --> 00:01:03,480
|
||||
Interested in our products? Contact us anytime.
|
||||
Yongkang Hongyu looks forward to working with you.
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 49 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 61 KiB |
@@ -0,0 +1,147 @@
|
||||
[
|
||||
{
|
||||
"start": 0.0,
|
||||
"end": 3.2,
|
||||
"text": "\u5927\u5bb6\u597d,\u6b22\u8fce\u6765\u5230\u6cf3\u6c64\u5e02\u7ea2\u57df\u516c\u8d38\u9c7c\u4ef7\u516c\u53f8"
|
||||
},
|
||||
{
|
||||
"start": 3.2,
|
||||
"end": 4.84,
|
||||
"text": "\u6211\u662f\u516c\u53f8\u8d1f\u8d23\u4eba"
|
||||
},
|
||||
{
|
||||
"start": 4.84,
|
||||
"end": 7.48,
|
||||
"text": "\u6211\u662f\u4e3b\u8981\u751f\u4ea7\u5706\u7075\u5de5\u5177"
|
||||
},
|
||||
{
|
||||
"start": 7.48,
|
||||
"end": 9.76,
|
||||
"text": "\u989d\u949e\u53ca\u6253\u8349\u5934\u53ca\u914d\u4ef6"
|
||||
},
|
||||
{
|
||||
"start": 9.76,
|
||||
"end": 12.64,
|
||||
"text": "\u63a5\u4e0b\u6765\u6211\u5e26\u5927\u5bb6\u53c2\u89c2\u4e00\u4e0b\u6211\u4eec\u5de5\u5382"
|
||||
},
|
||||
{
|
||||
"start": 12.64,
|
||||
"end": 14.84,
|
||||
"text": "\u6211\u4eec\u5de5\u5382\u6210\u7acb\u4e8e2020\u5e74"
|
||||
},
|
||||
{
|
||||
"start": 14.84,
|
||||
"end": 16.0,
|
||||
"text": "\u5458\u5de5\u670950\u4eba"
|
||||
},
|
||||
{
|
||||
"start": 16.0,
|
||||
"end": 19.24,
|
||||
"text": "\u5de5\u5382\u5730\u5740\u4f4d\u4e8e\u6cf3\u5eb7\u5e02\u53e4\u5c71\u9547\u4eba\u6cb3\u5ea62\u53f7"
|
||||
},
|
||||
{
|
||||
"start": 19.24,
|
||||
"end": 21.76,
|
||||
"text": "\u5360\u5730\u9762\u79ef\u8fbe\u52303800\u5e73\u65b9"
|
||||
},
|
||||
{
|
||||
"start": 21.76,
|
||||
"end": 24.56,
|
||||
"text": "\u62e5\u6709\u73b0\u4ee3\u5316\u5382\u623f\u548c\u5148\u8fdb\u7684\u8bbe\u5907"
|
||||
},
|
||||
{
|
||||
"start": 24.56,
|
||||
"end": 28.2,
|
||||
"text": "\u516c\u53f8\u4e3b\u8981\u751f\u4ea7\u6253\u8349\u5934\u53ca\u5706\u7075\u914d\u4ef6\u7b49\u4ea7\u54c1"
|
||||
},
|
||||
{
|
||||
"start": 28.28,
|
||||
"end": 31.4,
|
||||
"text": "\u5de5\u5382\u62e5\u6709\u4e13\u4e1a\u7684\u751f\u4ea7\u8bbe\u5907\u548c\u7814\u53d1\u56e2\u961f"
|
||||
},
|
||||
{
|
||||
"start": 31.4,
|
||||
"end": 32.88,
|
||||
"text": "\u9884\u4ea7\u91cf\u7ea62\u4e07\u4ef6"
|
||||
},
|
||||
{
|
||||
"start": 32.88,
|
||||
"end": 34.56,
|
||||
"text": "\u5ef6\u4ea7\u91cf\u7ea6600\u4e07\u4ef6"
|
||||
},
|
||||
{
|
||||
"start": 34.56,
|
||||
"end": 36.16,
|
||||
"text": "\u4ea7\u54c1\u8fdc\u6d88\u4fc4\u7f57\u65af"
|
||||
},
|
||||
{
|
||||
"start": 36.16,
|
||||
"end": 37.0,
|
||||
"text": "\u4e1c\u5357\u4e9a"
|
||||
},
|
||||
{
|
||||
"start": 37.0,
|
||||
"end": 38.48,
|
||||
"text": "\u6b27\u6d32\u56fd\u5bb6\u7ea7\u5730\u533a"
|
||||
},
|
||||
{
|
||||
"start": 38.48,
|
||||
"end": 40.4,
|
||||
"text": "OEM\u7b49\u4ee3\u5de5\u670d\u52a1"
|
||||
},
|
||||
{
|
||||
"start": 40.4,
|
||||
"end": 42.76,
|
||||
"text": "\u5de5\u5382\u4ece\u6765\u6599\u751f\u4ea7\u5230\u51fa\u8d27"
|
||||
},
|
||||
{
|
||||
"start": 42.76,
|
||||
"end": 45.4,
|
||||
"text": "\u6bcf\u4e2a\u73af\u8282\u5374\u4fdd\u51fa\u5382\u5546\u54c1\u8d28\u91cf\u8fc7\u786c"
|
||||
},
|
||||
{
|
||||
"start": 45.4,
|
||||
"end": 47.2,
|
||||
"text": "\u53ef\u4ee5\u627f\u63a5\u4ece\u8bbe\u8ba1\u7814\u53d1\u5230"
|
||||
},
|
||||
{
|
||||
"start": 47.2,
|
||||
"end": 49.44,
|
||||
"text": "\u751f\u4ea7\u5236\u9020\u4e00\u6218\u58ebODM"
|
||||
},
|
||||
{
|
||||
"start": 49.44,
|
||||
"end": 50.04,
|
||||
"text": "\u540c\u65f6"
|
||||
},
|
||||
{
|
||||
"start": 50.04,
|
||||
"end": 53.4,
|
||||
"text": "\u516c\u53f8\u4e3a\u56fd\u5185\u5916\u77e5\u540d\u54c1\u724c\u63d0\u4f9b\u4ee3\u5de5\u670d\u52a1"
|
||||
},
|
||||
{
|
||||
"start": 53.4,
|
||||
"end": 56.4,
|
||||
"text": "\u4ea7\u54c1\u8d28\u91cf\u83b7\u5f97\u884c\u4e1a\u4e70\u5bb6\u7684\u9ad8\u5ea6\u8ba4\u53ef"
|
||||
},
|
||||
{
|
||||
"start": 56.44,
|
||||
"end": 58.2,
|
||||
"text": "\u5982\u679c\u60a8\u5bf9\u6211\u4eec\u611f\u5174\u8da3"
|
||||
},
|
||||
{
|
||||
"start": 58.2,
|
||||
"end": 59.88,
|
||||
"text": "\u6b22\u8fce\u968f\u65f6\u8054\u7cfb\u6211\u4eec"
|
||||
},
|
||||
{
|
||||
"start": 59.88,
|
||||
"end": 62.2,
|
||||
"text": "\u6c38\u5eb7\u5e02\u7ea2\u57df\u5de5\u8d38\u6709\u9650\u516c\u53f8"
|
||||
},
|
||||
{
|
||||
"start": 62.2,
|
||||
"end": 63.48,
|
||||
"text": "\u671f\u5f85\u4e0e\u60a8\u5408\u4f5c"
|
||||
}
|
||||
]
|
||||
Reference in new issue
Block a user