# -*- 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%"), ("ebook_unlock_default", "ebook", f"{IMG_BASE}/ebook.png", 188, "旧默认道具 · 试读30%"), ("test", "test", f"{IMG_BASE}/test.png", 1, "联调测试道具 · ¥1"), ] OUT_DIRS = [ Path(r"c:\Users\Administrator\Desktop"), Path(__file__).resolve().parents[1] / "docs", ] 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()