24 lines
886 B
Python
24 lines
886 B
Python
#!/usr/bin/env python3
|
|
"""导入供应商基础数据"""
|
|
import csv, pymysql, importlib.util
|
|
|
|
spec = importlib.util.spec_from_file_location("config", "config.py")
|
|
config = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(config)
|
|
|
|
conn = pymysql.connect(**config.DB_CONFIG, cursorclass=pymysql.cursors.DictCursor)
|
|
|
|
with open('tmp_csv/jd-gys.csv', 'r', encoding='utf-8') as f:
|
|
rows = list(csv.DictReader(f))
|
|
print(f'读取到 {len(rows)} 条')
|
|
|
|
with conn.cursor() as cur:
|
|
for row in rows:
|
|
cur.execute(
|
|
"INSERT INTO suppliers (supplier_code, supplier_name, production_type) VALUES (%s, %s, %s) ON DUPLICATE KEY UPDATE supplier_name=VALUES(supplier_name), production_type=VALUES(production_type)",
|
|
(row['编码'].strip(), row['名称'].strip(), row['做货类型'].strip())
|
|
)
|
|
conn.commit()
|
|
conn.close()
|
|
print('导入完成 ✅')
|