upload
This commit is contained in:
+123
@@ -0,0 +1,123 @@
|
||||
import os.path
|
||||
import re
|
||||
|
||||
import pandas
|
||||
|
||||
import newsetting
|
||||
tent = newsetting.All_Setting('183.6.7.91', 23016, 'pyui_all_market')
|
||||
import time
|
||||
|
||||
timestamp = time.time()
|
||||
local_time = time.localtime(timestamp)
|
||||
current_date = time.strftime("%Y-%m-%d", local_time)
|
||||
|
||||
# workid 日期前缀,与下面 WORKID_ORG_MAP、主查询保持一致
|
||||
WORKID_PREFIX = '20260731_咸阳店'
|
||||
|
||||
# workid、业务码、门店 mt_org_id
|
||||
WORKID_ORG_MAP = [
|
||||
('20260625_喜地大厦', 'chengrenyongpin', '2DYRt4OFVmEgDKBjeKQORQI'),
|
||||
('20260625_喜地大厦', 'chengrenyongpin', 'JQkbjq43UI6Q8ieG4IRMyQI'),
|
||||
('20260625_喜地大厦', 'chengrenyongpin', 'VdSfezjBMxGnEPuFItXzqgI'),
|
||||
('20260625_喜地大厦', 'chengrenyongpin', 'cghDc3UskvfmMJ__xPS5kwI'),
|
||||
('20260625_喜地大厦', 'chengrenyongpin', '_qS0dKdD8kcsGS2GkMYhugI'),
|
||||
('20260625_喜地大厦', 'chengrenyongpin', 'O_0Z0YESkN5ZQLDi1lI7xAI'),
|
||||
('20260625_喜地大厦', 'chengrenyongpin', 'A3EoDTO9S66QC3PFmAGRpAI'),
|
||||
('20260625_喜地大厦', 'chengrenyongpin', 'IxEV31aiRHiGd0hmfjAWXwI'),
|
||||
('20260625_喜地大厦', 'chengrenyongpin', 'hncfDIwR39kIapw6JACK7AI'),
|
||||
('20260625_喜地大厦', 'chengrenyongpin', 'zv-BxAgFLMQwuO9CWz5AegI'),
|
||||
('20260625_湘域国际', 'chengrenyongpin', 'WLqfF8rDG6Xwklk4w-3NgAI'),
|
||||
('20260625_湘域国际', 'chengrenyongpin', '9eq-zIsVfrGy56XuwdBwiwI'),
|
||||
('20260625_湘域国际', 'chengrenyongpin', 'T_svZIbNkeRTTBUNAiPATwI'),
|
||||
('20260625_湘域国际', 'chengrenyongpin', 'b--gTTBNx6Ox9ZSQpZc9IwI'),
|
||||
('20260625_湘域国际', 'chengrenyongpin', 'kIQRCqwVfHLVSXRWMATNUAI'),
|
||||
('20260625_湘域国际', 'chengrenyongpin', 'c7zYrn7xrJAqlAOFc-e7KQI'),
|
||||
('20260625_湘域国际', 'chengrenyongpin', 'va8PuGdRRHxCD4ZPPeMAfAI'),
|
||||
('20260625_湘域国际', 'chengrenyongpin', 'l2eExP2iGaBf-ctYDCyy4QI'),
|
||||
('20260625_湘域国际', 'chengrenyongpin', 'OlkoZKlC9zsbkaDfXG9CWAI'),
|
||||
('20260625_湘域国际', 'chengrenyongpin', 'l8YdG5_ATPIbU8sXu_WWsgI'),
|
||||
('20260625_湘域国际', 'chengrenyongpin', 'hobwTnTB4-BMwyshyMofiQI'),
|
||||
('20260625_湘域国际', 'chengrenyongpin', 'FC3QKOrGcWW2L7ddlRJxHQI'),
|
||||
('20260625_湘域国际', 'chengrenyongpin', 'MuLbNjkHde4GrnWnN6EBOwI'),
|
||||
('20260625_湘域国际', 'chengrenyongpin', 'HimeqZraL56vSDdS2k7SMgI'),
|
||||
('20260625_百脑汇', 'chengrenyongpin', 'E8nMl-Ufc4E8EggOxCLVNAI'),
|
||||
('20260625_百脑汇', 'chengrenyongpin', 'rmek0D2laO2vEDi1CGIOgwI'),
|
||||
('20260625_百脑汇', 'chengrenyongpin', 'BYvVak2lk-mh_kwYZBLkVwI'),
|
||||
('20260625_百脑汇', 'chengrenyongpin', 'Rhdf5dRIYYO-GE6Y5t-YVgI'),
|
||||
]
|
||||
|
||||
TITLE = '一级分类名称,二级分类名称,商品名称,商品ID,SKU ID,upc编码,规格,活动价,原价,商品折扣,商品月售'.split(',')
|
||||
|
||||
|
||||
def sanitize_filename(name):
|
||||
"""清理文件名非法字符;仅用于保存 Excel,不要用于 SQL"""
|
||||
name = re.sub(r'[\\/:*?"<>|]', '_', name)
|
||||
name = name.strip(' .')
|
||||
return name or 'unnamed'
|
||||
|
||||
|
||||
def workid_folder_name(workid):
|
||||
if '_' in workid:
|
||||
return workid.split('_', 1)[1]
|
||||
return workid
|
||||
|
||||
|
||||
def get_workid(mt_org_id):
|
||||
for workid, _ti, mt_org_id2 in WORKID_ORG_MAP:
|
||||
if mt_org_id2 == mt_org_id:
|
||||
return workid
|
||||
return None
|
||||
|
||||
|
||||
def to_excel(rows, savename, business_code, workid):
|
||||
lb = []
|
||||
for i in rows:
|
||||
tag1_name, tag2_name, product_name, product_id, skus_id, upccode, spec, price, origin_price, promotion_info, month_saled_content, activity_price = i
|
||||
if price == origin_price:
|
||||
lb.append((tag1_name, tag2_name, product_name, product_id, skus_id, upccode, spec, activity_price, origin_price, promotion_info, month_saled_content))
|
||||
else:
|
||||
lb.append((tag1_name, tag2_name, product_name, product_id, skus_id, upccode, spec, price, origin_price, promotion_info, month_saled_content))
|
||||
|
||||
if not lb:
|
||||
return False
|
||||
|
||||
pa = pandas.DataFrame(lb, columns=TITLE)
|
||||
folder = workid_folder_name(workid)
|
||||
save_path = os.path.join('./', current_date, business_code, folder)
|
||||
os.makedirs(save_path, exist_ok=True)
|
||||
pa.to_excel(os.path.join(save_path, f'{savename}.xlsx'))
|
||||
return True
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sql = f"""
|
||||
SELECT DISTINCT shop_name, poi_id_str, workid
|
||||
FROM `ready_list2_copy1`
|
||||
WHERE workid LIKE '%{WORKID_PREFIX}%'"""
|
||||
|
||||
shopname_list = tent.get_shoppingmalls(sql)
|
||||
for shop_name, poi_id_str, db_workid in shopname_list:
|
||||
map_workid = get_workid(poi_id_str)
|
||||
workid = map_workid or db_workid
|
||||
if not map_workid:
|
||||
print(f'[映射外] {shop_name} | {poi_id_str} -> workid={db_workid}')
|
||||
|
||||
esc_shop = shop_name.replace("'", "''")
|
||||
sql2 = f"""
|
||||
SELECT tag1_name, tag2_name, product_name, product_id, skus_id, upccode, spec,
|
||||
price, origin_price, promotion_info, month_saled_content, activity_price
|
||||
FROM `ready_list2_copy1`
|
||||
WHERE workid like '%{workid}%'
|
||||
AND poi_id_str = '{poi_id_str}'
|
||||
AND shop_name = '{esc_shop}'
|
||||
ORDER BY tag1_name"""
|
||||
|
||||
da2 = tent.get_shoppingmalls(sql2)
|
||||
if not da2:
|
||||
print(f'[跳过] {workid} | {shop_name} | 无商品数据')
|
||||
continue
|
||||
|
||||
safe_name = sanitize_filename(shop_name)
|
||||
ok = to_excel(da2, safe_name, 'upc_all_20260626', workid)
|
||||
if ok:
|
||||
print(f'[导出] {workid} | {shop_name} -> {safe_name}.xlsx')
|
||||
Reference in New Issue
Block a user