Commit a9608cb34ff9ed65e9202f8feb5c46f770d5d02b
1 parent
50170c5a
1. 第一列“商品ID”这一列 进行填充,从1开始增
2. 如果变体的标题跟主商品不一致,请打印一条错误日志,并且忽略这一条数据
Showing
1 changed file
with
32 additions
and
3 deletions
Show diff stats
scripts/amazon_xlsx_to_shoplazza_xlsx.py
| ... | ... | @@ -458,16 +458,45 @@ def main(): |
| 458 | 458 | # 先按 SPU 构造每个组的行,方便做“按最大行数拆分但不拆组” |
| 459 | 459 | group_rows_list = [] # List[List[dict]] |
| 460 | 460 | spu_count = 0 |
| 461 | + next_product_id = 1 # 用于填充商品ID,全局自增 | |
| 462 | + | |
| 461 | 463 | for spu_id, variants in groups.items(): |
| 462 | 464 | if not variants: |
| 463 | 465 | continue |
| 466 | + | |
| 467 | + # 过滤掉标题与主商品不一致的变体 | |
| 468 | + main_title = variants[0].get("商品标题") or "" | |
| 469 | + filtered = [] | |
| 470 | + for v in variants: | |
| 471 | + title = v.get("商品标题") or "" | |
| 472 | + if main_title and title and title != main_title: | |
| 473 | + print( | |
| 474 | + f"SKIP variant due to title mismatch: SPU={spu_id}, ASIN={v.get('ASIN')}, " | |
| 475 | + f"main_title='{main_title}', variant_title='{title}'", | |
| 476 | + flush=True, | |
| 477 | + ) | |
| 478 | + continue | |
| 479 | + filtered.append(v) | |
| 480 | + | |
| 481 | + if not filtered: | |
| 482 | + # 整个SPU都被过滤掉 | |
| 483 | + continue | |
| 484 | + | |
| 464 | 485 | spu_count += 1 |
| 465 | 486 | if args.max_products is not None and spu_count > int(args.max_products): |
| 466 | 487 | break |
| 467 | - if len(variants) == 1: | |
| 468 | - group_rows_list.append([build_s_row(variants[0])]) | |
| 488 | + | |
| 489 | + if len(filtered) == 1: | |
| 490 | + rows = [build_s_row(filtered[0])] | |
| 469 | 491 | else: |
| 470 | - group_rows_list.append(build_m_p_rows(variants)) | |
| 492 | + rows = build_m_p_rows(filtered) | |
| 493 | + | |
| 494 | + # 填充商品ID(从1开始全局递增) | |
| 495 | + for r in rows: | |
| 496 | + r["商品ID"] = next_product_id | |
| 497 | + next_product_id += 1 | |
| 498 | + | |
| 499 | + group_rows_list.append(rows) | |
| 471 | 500 | |
| 472 | 501 | # 按最大行数拆成多个文件(注意:同一 SPU 不拆分) |
| 473 | 502 | data_start_row = 4 # 与模板/写入工具保持一致 | ... | ... |