增加挂载商品映射配置
This commit is contained in:
parent
3bab25f983
commit
bb95da24d4
|
|
@ -43,6 +43,14 @@ python main.py
|
|||
- 输入 `1` 启动采集。程序会自动寻找本机安装的 Chrome 或 Edge 浏览器。
|
||||
- 输入 `2` 启动处理。
|
||||
|
||||
## 配置文件
|
||||
|
||||
- `product_map.txt`: 商品名称映射配置文件。
|
||||
- 程序首次运行时会自动生成此文件。
|
||||
- 用于解决商城商品名称与货易通系统商品名称不一致的问题。
|
||||
- 格式:`商城商品名=内部商品名`,每行一条。
|
||||
- 支持 `#` 开头的注释。
|
||||
|
||||
## Windows 打包指南 (便携式打包 - 无需安装Python)
|
||||
|
||||
如果你不想在 Windows 系统中安装 Python,可以使用以下脚本进行一次性打包。
|
||||
|
|
|
|||
|
|
@ -57,8 +57,16 @@ Write-Host "[Step 4/6] Installing dependencies..." -ForegroundColor Cyan
|
|||
|
||||
Write-Host "[Step 5/6] Building executable..." -ForegroundColor Cyan
|
||||
# Run PyInstaller
|
||||
# --add-data "src;dest": 将文件打包到目录中 (Windows 用 ; 分隔)
|
||||
# 这里我们希望 product_map.txt 和 使用说明.txt 都在输出目录中
|
||||
# PyInstaller 的 --onedir 模式下,非代码资源如果不指定,不会自动复制到 dist
|
||||
& $PythonExe -m PyInstaller --noconfirm --onedir --console --clean --name "scbank_tool" main.py
|
||||
|
||||
# 手动复制配置文件到发布目录 (比 --add-data 更直观,因为用户需要编辑)
|
||||
Write-Host "Copying configuration files..." -ForegroundColor Gray
|
||||
Copy-Item "product_map.txt" -Destination "dist\scbank_tool\" -Force
|
||||
Copy-Item "使用说明.txt" -Destination "dist\scbank_tool\" -Force
|
||||
|
||||
if ($LASTEXITCODE -eq 0) {
|
||||
Write-Host "[Success] Build completed successfully!" -ForegroundColor Green
|
||||
Write-Host "Executable location: dist\scbank_tool\scbank_tool.exe"
|
||||
|
|
|
|||
2
main.py
2
main.py
|
|
@ -6,7 +6,7 @@ def main():
|
|||
while True:
|
||||
print("\n=== 四川银行权益商城自动化工具 ===")
|
||||
print("1. 启动采集 (Collector) -> 浏览器抓取")
|
||||
print("2. 执行同步 (Processor) -> 内部系统上传")
|
||||
print("2. 执行同步 (Processor) -> 货易通上传")
|
||||
print("3. 退出")
|
||||
choice = input("请输入选项 [1-3]: ").strip()
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
# 商品名称映射配置文件
|
||||
#
|
||||
# 作用:解决“商城商品名称”与“货易通系统商品名称”不一致导致无法匹配的问题。
|
||||
#
|
||||
# 格式说明:
|
||||
# 1. 每一行代表一条映射规则。
|
||||
# 2. 使用 ">>>>" (四个大于号) 作为分隔符。
|
||||
# 格式:商城商品名称>>>>内部商品名称
|
||||
# 3. 如果某行以 "#" 开头,则被视为注释,程序会忽略。
|
||||
#
|
||||
# 示例:
|
||||
#
|
||||
# 商城显示名称>>>>货易通系统实际名称
|
||||
# 四川特产/老腊肉=500g>>>>精选老腊肉(500g)
|
||||
# 某某大米:10kg装>>>>东北大米-10kg
|
||||
#
|
||||
# --- 请在下方添加您的配置 ---
|
||||
|
|
@ -22,6 +22,40 @@ class InternalApiClient:
|
|||
# 测试环境 (默认)
|
||||
# self.app_id = "e699e6ef74504f4d86776b3d244ce602"
|
||||
|
||||
# 加载商品映射配置
|
||||
self.product_map = self._load_product_map()
|
||||
|
||||
def _load_product_map(self):
|
||||
"""加载商品名称映射文件 (product_map.txt)"""
|
||||
mapping = {}
|
||||
map_file = "product_map.txt"
|
||||
|
||||
# 不再自动生成文件,避免覆盖用户配置
|
||||
if not os.path.exists(map_file):
|
||||
print(f"[Warn] 未找到映射配置文件: {map_file},将使用原始名称匹配")
|
||||
return mapping
|
||||
|
||||
try:
|
||||
with open(map_file, "r", encoding="utf-8") as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
# 跳过注释和空行
|
||||
if not line or line.startswith("#"): continue
|
||||
|
||||
# 使用 ">>>>" 作为分隔符,因为它非常罕见,不可能是商品名的一部分
|
||||
sep = ">>>>"
|
||||
if sep in line:
|
||||
parts = line.split(sep, 1)
|
||||
key = parts[0].strip()
|
||||
val = parts[1].strip()
|
||||
if key and val:
|
||||
mapping[key] = val
|
||||
print(f"[Info] 已加载 {len(mapping)} 条商品映射规则")
|
||||
except Exception as e:
|
||||
print(f"[Warn] 加载映射文件失败: {e}")
|
||||
|
||||
return mapping
|
||||
|
||||
def _post(self, path, data):
|
||||
"""发送 POST 请求"""
|
||||
url = f"{self.api_base_url}{path}"
|
||||
|
|
@ -47,8 +81,14 @@ class InternalApiClient:
|
|||
"""
|
||||
if not scbank_goods_name: return None
|
||||
|
||||
# 0. 优先使用映射
|
||||
search_name = scbank_goods_name
|
||||
if scbank_goods_name in self.product_map:
|
||||
search_name = self.product_map[scbank_goods_name]
|
||||
print(f"[Map] 使用映射: '{scbank_goods_name}' -> '{search_name}'")
|
||||
|
||||
payload = {
|
||||
"title": scbank_goods_name,
|
||||
"title": search_name,
|
||||
"page": 1,
|
||||
"limit": 10
|
||||
}
|
||||
|
|
@ -66,7 +106,7 @@ class InternalApiClient:
|
|||
if product_list and len(product_list) == 1:
|
||||
return product_list[0].get("goods_num")
|
||||
else:
|
||||
print(f"[Match Fail] '{scbank_goods_name}' 匹配到 {len(product_list)} 个商品")
|
||||
print(f"[Match Fail] '{search_name}' 匹配到 {len(product_list)} 个商品")
|
||||
return None
|
||||
|
||||
return None
|
||||
|
|
|
|||
|
|
@ -0,0 +1,51 @@
|
|||
========================================================================
|
||||
四川银行权益商城自动化工具 - 使用说明
|
||||
========================================================================
|
||||
|
||||
一、 快速开始
|
||||
|
||||
1. 确保您的电脑已连接互联网。
|
||||
2. 确保您的电脑已安装 Google Chrome 或 Microsoft Edge 浏览器。
|
||||
3. 双击运行文件夹中的 "scbank_tool.exe"。
|
||||
4. 按照屏幕提示操作:
|
||||
- 输入 "1" 并回车:启动采集。程序会自动打开浏览器,请登录后进入订单页面,选择下单时间后点击查询,程序会自动抓取数据。
|
||||
- 输入 "2" 并回车:启动处理。程序会自动读取抓取到的数据,上传到货易通系统,并生成 Excel 报表。
|
||||
|
||||
二、 文件结构说明
|
||||
|
||||
- scbank_tool.exe : 主程序,双击运行。
|
||||
- product_map.txt : 商品名称映射配置文件 (文本文件,可用记事本编辑)。
|
||||
- data/ : [自动生成] 存放采集到的原始数据 (.jsonl)。
|
||||
- data/archive/ : [自动生成] 存放处理完成并归档的数据。
|
||||
- output/ : [自动生成] 存放处理结果和 Excel 报表。
|
||||
- error.log : [自动生成] 如果程序闪退或出错,错误信息会保存在这里。
|
||||
|
||||
三、 商品名称映射配置 (重要)
|
||||
|
||||
如果商城显示的商品名称,与货易通系统中的商品名称不一致,会导致“商品匹配失败”。
|
||||
此时,您需要手动编辑 "product_map.txt" 文件。
|
||||
|
||||
1. 用记事本打开 "product_map.txt"。
|
||||
2. 在文件末尾添加一行规则。
|
||||
3. 规则格式:
|
||||
商城商品名称>>>>内部商品名称
|
||||
|
||||
(注意:中间是四个大于号 >>>>)
|
||||
|
||||
4. 示例:
|
||||
如果商城显示 "四川特产/老腊肉(500g)",而货易通系统叫 "精选老腊肉",则添加:
|
||||
|
||||
四川特产/老腊肉(500g)>>>>精选老腊肉
|
||||
|
||||
5. 保存文件后,重新运行程序即可生效。
|
||||
|
||||
四、 常见问题
|
||||
|
||||
Q: 程序一打开就闪退?
|
||||
A: 请检查文件夹下是否生成了 error.log 文件,打开查看具体错误。通常是因为电脑没有安装 Chrome/Edge 浏览器,或者网络不通。
|
||||
|
||||
Q: 采集时浏览器没有自动翻页?
|
||||
A: 请确保浏览器窗口保持在前台,不要最小化。如果页面加载过慢,程序可能会等待超时。
|
||||
|
||||
Q: 上传失败提示“未找到商品”?
|
||||
A: 请检查 product_map.txt,添加对应的名称映射规则。
|
||||
Loading…
Reference in New Issue