nomadro/apps/miniprogram/scripts/gen_wx_props_batch_xlsx.py
Eric 362dab20f6 Keep WeChat props batch xlsx in-repo under docs/wx-props-batch for reuse.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-22 11:05:57 +08:00

71 lines
2.6 KiB
Python

# -*- coding: utf-8 -*-
"""Generate WeChat MP virtual-pay batch props xlsx (example_batch_add_product format)."""
from __future__ import annotations
from pathlib import Path
import openpyxl
from openpyxl.styles import Alignment, Font
# SoT: apps/api/.../products.py (paid only)
# 价格单位:元(整数);图片须可被 mp.weixin.qq.com CORS 拉取
IMG_BASE = "https://admin.nomadro.cn/props"
ROWS = [
# (道具id, 道具名称≤10字, 图片URL, 价格元, 备注≤50)
("tiktok", "tiktok", f"{IMG_BASE}/tiktok.png", 88, "已发布方案 · 试读30%"),
("youtube", "youtube", f"{IMG_BASE}/youtube.png", 188, "默认付费方案 · 试读30%"),
("nomad", "nomad", f"{IMG_BASE}/nomad.png", 49, "已发布方案 · 试读30%"),
("svip", "svip", f"{IMG_BASE}/svip.png", 998, "已发布方案 · 试读30%"),
("29", "29", f"{IMG_BASE}/29.png", 29, "新方案 · ¥29 · 试读30%"),
("298", "298", f"{IMG_BASE}/298.png", 298, "新方案 · ¥298 · 试读30%"),
("588", "588", f"{IMG_BASE}/588.png", 588, "新方案 · ¥588 · 试读30%"),
("ebook_unlock_default", "ebook", f"{IMG_BASE}/ebook.png", 188, "旧默认道具 · 试读30%"),
("test", "test", f"{IMG_BASE}/test.png", 1, "联调测试道具 · ¥1"),
]
_DOCS = Path(__file__).resolve().parents[1] / "docs"
OUT_DIRS = [
_DOCS / "wx-props-batch", # 项目内固定目录(下次直接用)
_DOCS, # 短路径副本
Path(r"c:\Users\Administrator\Desktop"), # 桌面方便上传
]
def main() -> None:
wb = openpyxl.Workbook()
ws = wb.active
ws.title = "Sheet1"
headers = ["道具id", "道具名称", "道具图片", "道具价格", "备注"]
ws.append(headers)
for cell in ws[1]:
cell.font = Font(bold=True)
cell.alignment = Alignment(wrap_text=True)
for row in ROWS:
# validate
pid, name, url, price, remark = row
assert len(pid) <= 32 and pid.isascii() and pid.replace("_", "").isalnum()
assert len(name) <= 10
assert url.lower().endswith((".png", ".jpg", ".jpeg"))
assert isinstance(price, int) and 1 <= price <= 10000
assert len(remark) <= 50
ws.append(list(row))
ws.column_dimensions["A"].width = 24
ws.column_dimensions["B"].width = 14
ws.column_dimensions["C"].width = 56
ws.column_dimensions["D"].width = 12
ws.column_dimensions["E"].width = 28
name = "nomadro_wx_props_batch_upload.xlsx"
for d in OUT_DIRS:
d.mkdir(parents=True, exist_ok=True)
path = d / name
wb.save(path)
print("wrote", path, "rows", len(ROWS))
if __name__ == "__main__":
main()