upload
This commit is contained in:
@@ -0,0 +1,146 @@
|
||||
import re
|
||||
import pymysql
|
||||
|
||||
class All_Setting():
|
||||
def __init__(self,host,port,db):
|
||||
self.host = host
|
||||
self.port = port
|
||||
self.db = db
|
||||
|
||||
def remove_symbols(self,text):
|
||||
pattern = re.compile(r'[^\w\s]')
|
||||
return pattern.sub('', text)
|
||||
|
||||
def get_chinese(self,text,printTxt=False):
|
||||
# text = "海王星辰(广州智慧城店)"
|
||||
pattern = r'[^\w\s]'
|
||||
result = re.sub(pattern, '', text)
|
||||
if printTxt:
|
||||
print(result)
|
||||
return result
|
||||
|
||||
def get_shoppingmalls(self,sql):
|
||||
res_list = []
|
||||
conn = pymysql.connect(
|
||||
host= self.host, # 我的IP地址
|
||||
port=self.port, # 不是字符串不需要加引号。
|
||||
user='root',
|
||||
password='Aliyun@7646!',
|
||||
db=self.db,
|
||||
charset='utf8mb4'
|
||||
)
|
||||
if conn:
|
||||
print('ok')
|
||||
cursor = conn.cursor()
|
||||
res = cursor.execute(sql)
|
||||
c2 = cursor.fetchall()
|
||||
return c2
|
||||
|
||||
def write_data(self,sql,data):
|
||||
conn = pymysql.connect(
|
||||
host= self.host, # 我的IP地址
|
||||
port=self.port, # 不是字符串不需要加引号。
|
||||
user='root',
|
||||
password='Aliyun@7646!',
|
||||
db=self.db,
|
||||
charset='utf8mb4'
|
||||
)
|
||||
# 拿到游标
|
||||
if conn:
|
||||
print("连接成功!")
|
||||
cursor = conn.cursor()
|
||||
cursor.executemany(sql,data)
|
||||
conn.commit()
|
||||
cursor.close()
|
||||
|
||||
|
||||
def update_data(self,sql):
|
||||
conn = pymysql.connect(
|
||||
host= self.host, # 我的IP地址
|
||||
port=self.port, # 不是字符串不需要加引号。
|
||||
user='root',
|
||||
password='Aliyun@7646!',
|
||||
db=self.db,
|
||||
charset='utf8mb4'
|
||||
)
|
||||
# 拿到游标
|
||||
if conn:
|
||||
print("连接成功!")
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(sql)
|
||||
conn.commit()
|
||||
cursor.close()
|
||||
|
||||
def write_data_one(self,sql,data):
|
||||
conn = pymysql.connect(
|
||||
host= self.host, # 我的IP地址
|
||||
port=self.port, # 不是字符串不需要加引号。
|
||||
user='root',
|
||||
password='Aliyun@7646!',
|
||||
db=self.db,
|
||||
charset='utf8mb4'
|
||||
)
|
||||
# 拿到游标
|
||||
if conn:
|
||||
print("连接成功!")
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(sql,data)
|
||||
conn.commit()
|
||||
cursor.close()
|
||||
|
||||
import json
|
||||
import time,requests
|
||||
|
||||
|
||||
def get_sign_meituan(url, dfpid, data):
|
||||
url_mtg = "http://118.89.119.254:18003/mt_jym_1_2"
|
||||
payload = json.dumps({
|
||||
"url": url,
|
||||
"data": data,
|
||||
"dfpid": dfpid,
|
||||
"method": "POST",
|
||||
"ua_type": "android"
|
||||
})
|
||||
headers = {
|
||||
'token': 'j760kynsopjfm0sa9ghjwsd',
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
response1 = requests.request("POST", url_mtg, headers=headers, data=payload)
|
||||
print(response1.text)
|
||||
mtgsig1 = response1.json()
|
||||
return str(mtgsig1)
|
||||
|
||||
def get_sign_waimai(url, dfpid, data):
|
||||
print('我是外卖mtg')
|
||||
|
||||
url_mtg = "http://118.89.119.254:18003/get_mt_tg_0507_jym"
|
||||
payload = json.dumps({
|
||||
"url": url,
|
||||
"data": data,
|
||||
"dfpid": dfpid,
|
||||
"method": "POST",
|
||||
# "ua_type": "android"
|
||||
})
|
||||
headers = {
|
||||
'token': 'j760kynsopjfm0sa9ghjwsd',
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
response = requests.request("POST", url_mtg, headers=headers, data=payload)
|
||||
mtgsig = response.json()
|
||||
print(mtgsig)
|
||||
return str(mtgsig)
|
||||
|
||||
def get_Datatext(dataq):
|
||||
str1 = ''
|
||||
for i in dataq:
|
||||
key, value = i, dataq[i]
|
||||
str2 = f'{key}={value}&'
|
||||
str1 = str1 + str2
|
||||
data = str1[0:-1]
|
||||
return data
|
||||
|
||||
|
||||
# 名称医乐邦
|
||||
# 请输入坐标34.268453,117.165798
|
||||
+229
@@ -0,0 +1,229 @@
|
||||
import multiprocessing
|
||||
import json
|
||||
import newsetting
|
||||
import time
|
||||
|
||||
# 数据库配置
|
||||
DB_HOST = '192.168.5.2'
|
||||
DB_PORT = 3307
|
||||
DB_NAME = 'mt_newretail'
|
||||
# workid = '20260409'
|
||||
# workid = '20260409_test3'
|
||||
workid = '20261116'
|
||||
|
||||
# 进程私有变量
|
||||
process_tent = None
|
||||
poi_filter_config = {} # 只存配置表中的店铺
|
||||
|
||||
|
||||
def init_worker():
|
||||
global process_tent, poi_filter_config
|
||||
process_tent = newsetting.All_Setting(DB_HOST, DB_PORT, DB_NAME)
|
||||
poi_filter_config = load_poi_filters()
|
||||
|
||||
|
||||
def load_poi_filters():
|
||||
"""加载配置表中的店铺筛选配置"""
|
||||
temp_tent = newsetting.All_Setting(DB_HOST, DB_PORT, DB_NAME)
|
||||
|
||||
# 读取配置表(workid=20260302)
|
||||
sql = f"""
|
||||
SELECT poi_id_str, shop_name, tag1, tag1_name, tag2, tag2_name
|
||||
FROM poi_category_filter
|
||||
WHERE workid = '{workid}'
|
||||
"""
|
||||
result = temp_tent.get_shoppingmalls(sql)
|
||||
|
||||
# 建立 shop_name -> 分类配置
|
||||
filters_by_name = {}
|
||||
for row in result:
|
||||
poi_id, shop_name, tag1, tag1_name, tag2, tag2_name = row
|
||||
shop_key = shop_name.strip() if shop_name else ''
|
||||
|
||||
if shop_key not in filters_by_name:
|
||||
filters_by_name[shop_key] = []
|
||||
|
||||
filters_by_name[shop_key].append({
|
||||
'tag1': tag1,
|
||||
'tag1_name': tag1_name.strip() if tag1_name else None,
|
||||
'tag2': tag2,
|
||||
'tag2_name': tag2_name.strip() if tag2_name else None
|
||||
})
|
||||
|
||||
print(f"配置表中共有 {len(filters_by_name)} 个不同店名")
|
||||
|
||||
# 匹配当前workid中的poi_id_str
|
||||
filters = {}
|
||||
if filters_by_name:
|
||||
shop_names = "','".join([k.replace("'", "''") for k in filters_by_name.keys()])
|
||||
poi_sql = f"""
|
||||
SELECT DISTINCT poi_id_str, shop_name
|
||||
FROM food_table
|
||||
WHERE workid like '%{workid}%' AND shop_name IN ('{shop_names}')
|
||||
"""
|
||||
poi_result = temp_tent.get_shoppingmalls(poi_sql)
|
||||
|
||||
for poi_id, shop_name in poi_result:
|
||||
shop_key = shop_name.strip() if shop_name else ''
|
||||
if shop_key in filters_by_name:
|
||||
filters[poi_id] = {
|
||||
'shop_name': shop_name,
|
||||
'categories': filters_by_name[shop_key]
|
||||
}
|
||||
|
||||
print(f"已匹配到 {len(filters)} 个门店需要筛选")
|
||||
return filters
|
||||
|
||||
|
||||
def match_category(cat_tag1_name, cat_tag2_name, config):
|
||||
"""按分类名字匹配,'全部'或None表示不限制"""
|
||||
cfg_tag1_name = config.get('tag1_name')
|
||||
cfg_tag2_name = config.get('tag2_name')
|
||||
|
||||
match_tag1 = (cfg_tag1_name is None) or (cfg_tag1_name == '全部') or \
|
||||
(cat_tag1_name and cat_tag1_name.strip() == cfg_tag1_name)
|
||||
|
||||
match_tag2 = (cfg_tag2_name is None) or (cfg_tag2_name == '全部') or \
|
||||
(cat_tag2_name and cat_tag2_name.strip() == cfg_tag2_name)
|
||||
|
||||
return match_tag1 and match_tag2
|
||||
|
||||
|
||||
def get_data_batch(poi_ids):
|
||||
"""批量获取数据"""
|
||||
poi_str = "','".join(poi_ids)
|
||||
|
||||
cat_sql = f"""
|
||||
SELECT t1.parent_id,t1.workid,t1.business_code,t1.mt_org_id,t1.poi_id_str,t1.shop_name,t1.address,t1.shipping_fee_tip,t1.min_price_tip,t1.packet_fee_tip,t1.shipping_time,t2.tag1,t2.tag1_name,t2.tag2,t2.tag2_name,t2.tag_type,t2.product_count,t2.allSortedSpuId
|
||||
from (SELECT * FROM food_table WHERE workid like '%{workid}%' and poi_id_str IN ('{poi_str}')) AS t1
|
||||
INNER JOIN (SELECT * FROM categorylist WHERE workid like '%{workid}%' AND is_ok = 1 and poi_id_str IN ('{poi_str}')) as t2
|
||||
ON t1.poi_id_str = t2.poi_id_str AND t1.mt_org_id <=> t2.mt_org_id
|
||||
"""
|
||||
categories = process_tent.get_shoppingmalls(cat_sql)
|
||||
|
||||
prod_sql = f"""
|
||||
SELECT poi_id_str, product_id,product_name,description,praise_content,month_saled_content,skus_id,spec,actual_price,price,origin_price,activity_price,min_order_count,quota_per_order,dynamic_text,dynamic_url,upccode,want_to_buy_content,praise_rate,picture,promotion_info,tag,activity_tag_id,stock_label,real_stock,skus_count,product_label,vague_picture,create_time
|
||||
FROM `mt_newretail`.`productslist`
|
||||
where workid like '%{workid}%' and poi_id_str IN ('{poi_str}')
|
||||
"""
|
||||
products = process_tent.get_shoppingmalls(prod_sql)
|
||||
|
||||
# 筛选分类:配置表有的按配置筛,没有的不筛(保留全部)
|
||||
filtered_categories = []
|
||||
for cat in categories:
|
||||
poi_id = cat[4]
|
||||
cat_tag1_name = cat[12] if cat[12] else None
|
||||
cat_tag2_name = cat[14] if cat[14] else None
|
||||
|
||||
# 配置表中没有这个店铺 -> 保留所有分类(原逻辑)
|
||||
if poi_id not in poi_filter_config:
|
||||
filtered_categories.append(cat)
|
||||
continue
|
||||
|
||||
# 配置表中有这个店铺 -> 按配置筛选
|
||||
category_configs = poi_filter_config[poi_id]['categories']
|
||||
for cfg in category_configs:
|
||||
if match_category(cat_tag1_name, cat_tag2_name, cfg):
|
||||
filtered_categories.append(cat)
|
||||
break
|
||||
|
||||
return filtered_categories, products
|
||||
|
||||
|
||||
def process_batch_task(poi_ids):
|
||||
"""处理一批门店的数据"""
|
||||
try:
|
||||
categories, products = get_data_batch(poi_ids)
|
||||
if not categories or not products:
|
||||
return poi_ids, []
|
||||
|
||||
# 建立商品索引
|
||||
product_index = {}
|
||||
for p in products:
|
||||
poi_id = p[0]
|
||||
prod_data = p[1:]
|
||||
if poi_id not in product_index:
|
||||
product_index[poi_id] = {}
|
||||
product_index[poi_id][str(prod_data[0])] = prod_data
|
||||
|
||||
local_results = []
|
||||
for cat in categories:
|
||||
poi_id = cat[4]
|
||||
if poi_id not in product_index:
|
||||
continue
|
||||
|
||||
try:
|
||||
all_spu_json = cat[-1]
|
||||
spu_ids = json.loads(all_spu_json)
|
||||
for spu_id in spu_ids:
|
||||
spu_id_str = str(spu_id)
|
||||
if spu_id_str in product_index[poi_id]:
|
||||
prod = product_index[poi_id][spu_id_str]
|
||||
local_results.append(cat + prod)
|
||||
except:
|
||||
continue
|
||||
|
||||
print(f'[{time.strftime("%H:%M:%S")}] 批次完成: {len(poi_ids)} 门店, 匹配: {len(local_results)} 条')
|
||||
return poi_ids, local_results
|
||||
except Exception as e:
|
||||
print(f"批次处理出错: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
return poi_ids, []
|
||||
|
||||
|
||||
def main():
|
||||
global poi_filter_config
|
||||
|
||||
# 1. 加载筛选配置(只包含有配置的店铺)
|
||||
poi_filter_config = load_poi_filters()
|
||||
|
||||
# 2. 获取所有门店(原逻辑)
|
||||
temp_tent = newsetting.All_Setting(DB_HOST, DB_PORT, DB_NAME)
|
||||
task = temp_tent.get_shoppingmalls(f"SELECT DISTINCT poi_id_str FROM food_table WHERE workid like '%{workid}%' and business_code ='chengrenyongpin' ")
|
||||
# task = temp_tent.get_shoppingmalls(f"SELECT DISTINCT poi_id_str FROM food_table WHERE workid = '{workid}' ")
|
||||
all_poi_ids = [i[0] for i in task]
|
||||
print(
|
||||
f"总共有 {len(all_poi_ids)} 个门店,其中 {len(poi_filter_config)} 个需要筛选,{len(all_poi_ids) - len(poi_filter_config)} 个按原逻辑处理")
|
||||
|
||||
# 3. 分组处理所有门店
|
||||
batch_size = 20
|
||||
poi_batches = [all_poi_ids[i:i + batch_size] for i in range(0, len(all_poi_ids), batch_size)]
|
||||
print(f"共分成 {len(poi_batches)} 个批次")
|
||||
|
||||
# 4. 准备写入
|
||||
final_tent = newsetting.All_Setting(DB_HOST, DB_PORT, DB_NAME)
|
||||
insert_sql = """
|
||||
insert into ready_list2_copy1 (parent_id,workid,business_code,mt_org_id, poi_id_str, shop_name, address, shipping_fee_tip, min_price_tip, packet_fee_tip, shipping_time, tag1, tag1_name, tag2, tag2_name, tag_type, product_count, allSortedSpuId,product_id, product_name, description, praise_content, month_saled_content, skus_id,spec, actual_price, price, origin_price, activity_price, min_order_count, quota_per_order, dynamic_text, dynamic_url, upccode, want_to_buy_content, praise_rate, picture, promotion_info, tag, activity_tag_id, stock_label, real_stock, skus_count, product_label, vague_picture,create_time) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)
|
||||
"""
|
||||
|
||||
# 5. 启动进程池
|
||||
num_processes = 32
|
||||
total_written = 0
|
||||
|
||||
with multiprocessing.Pool(processes=num_processes, initializer=init_worker) as pool:
|
||||
for handled_ids, res_list in pool.imap_unordered(process_batch_task, poi_batches):
|
||||
try:
|
||||
ids_str = "','".join(handled_ids)
|
||||
update_sql = f"UPDATE food_table SET is_ok = 1 WHERE workid like '%{workid}%' AND poi_id_str IN ('{ids_str}')"
|
||||
final_tent.update_data(update_sql)
|
||||
except Exception as e:
|
||||
print(f"更新状态失败: {e}")
|
||||
if res_list:
|
||||
try:
|
||||
final_tent.write_data(insert_sql, res_list)
|
||||
total_written += len(res_list)
|
||||
print(f'>>> 已写入数据库: {len(res_list)} 条 (累计: {total_written} 条)')
|
||||
del res_list
|
||||
except Exception as e:
|
||||
print(f"写入数据库失败: {e}")
|
||||
print(f"[{time.strftime('%H:%M:%S')}] 完成,共计 {total_written} 条数据。")
|
||||
|
||||
# temp_tent.update_data(f"UPDATE ready_list2_copy1 SET business_code ='SURPERMARKET' WHERE business_code = 'SURPERMARKET1' and workid ='{workid}'")
|
||||
# print('月报更新')
|
||||
|
||||
|
||||
|
||||
# 110809
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,153 @@
|
||||
from __future__ import annotations
|
||||
|
||||
"""
|
||||
productslist_search → ready_list2_copy1
|
||||
搜索商品没有分类 allSortedSpuId,店铺信息从 food_table 拼;keyword 用 productslist_search.key_word
|
||||
"""
|
||||
|
||||
import multiprocessing
|
||||
import time
|
||||
|
||||
import newsetting
|
||||
|
||||
# ==================== 运行参数(改这里) ====================
|
||||
DB_HOST = '192.168.5.2'
|
||||
DB_PORT = 3307
|
||||
DB_NAME = 'mt_newretail'
|
||||
workid = '20260904'
|
||||
BATCH_SIZE = 20
|
||||
NUM_PROCESSES = 32
|
||||
# ============================================================
|
||||
|
||||
process_tent = None
|
||||
|
||||
|
||||
def init_worker():
|
||||
global process_tent
|
||||
process_tent = newsetting.All_Setting(DB_HOST, DB_PORT, DB_NAME)
|
||||
|
||||
|
||||
def get_data_batch(poi_ids):
|
||||
"""按门店拉店铺信息 + 搜索商品,直接拼成 ready_list2_copy1 行"""
|
||||
poi_str = "','".join(poi_ids)
|
||||
|
||||
sql = f"""
|
||||
SELECT
|
||||
t1.parent_id,
|
||||
t1.workid,
|
||||
t1.business_code,
|
||||
t1.mt_org_id,
|
||||
t1.poi_id_str,
|
||||
t1.shop_name,
|
||||
t1.address,
|
||||
t1.shipping_fee_tip,
|
||||
t1.min_price_tip,
|
||||
t1.packet_fee_tip,
|
||||
t1.shipping_time,
|
||||
NULL AS tag1,
|
||||
NULL AS tag1_name,
|
||||
NULL AS tag2,
|
||||
NULL AS tag2_name,
|
||||
NULL AS tag_type,
|
||||
NULL AS product_count,
|
||||
NULL AS allSortedSpuId,
|
||||
t2.product_id,
|
||||
t2.product_name,
|
||||
t2.description,
|
||||
t2.praise_content,
|
||||
t2.month_saled_content,
|
||||
t2.skus_id,
|
||||
t2.spec,
|
||||
t2.actual_price,
|
||||
t2.price,
|
||||
t2.origin_price,
|
||||
t2.activity_price,
|
||||
t2.min_order_count,
|
||||
t2.quota_per_order,
|
||||
t2.dynamic_text,
|
||||
t2.dynamic_url,
|
||||
t2.upccode,
|
||||
t2.want_to_buy_content,
|
||||
t2.praise_rate,
|
||||
t2.picture,
|
||||
t2.promotion_info,
|
||||
t2.tag,
|
||||
t2.activity_tag_id,
|
||||
t2.stock_label,
|
||||
t2.real_stock,
|
||||
NULL AS skus_count,
|
||||
t2.product_label,
|
||||
t2.vague_picture,
|
||||
t2.create_time,
|
||||
t2.key_word
|
||||
FROM (
|
||||
SELECT * FROM food_table
|
||||
WHERE workid LIKE '%{workid}%' AND poi_id_str IN ('{poi_str}')
|
||||
) AS t1
|
||||
INNER JOIN (
|
||||
SELECT * FROM productslist_search
|
||||
WHERE workid LIKE '%{workid}%' AND poi_id_str IN ('{poi_str}')
|
||||
) AS t2
|
||||
ON t1.poi_id_str = t2.poi_id_str
|
||||
AND t1.mt_org_id <=> t2.mt_org_id
|
||||
"""
|
||||
rows = process_tent.get_shoppingmalls(sql)
|
||||
return rows or []
|
||||
|
||||
|
||||
def process_batch_task(poi_ids):
|
||||
try:
|
||||
rows = get_data_batch(poi_ids)
|
||||
print(f'[{time.strftime("%H:%M:%S")}] 批次完成: {len(poi_ids)} 门店, 匹配: {len(rows)} 条')
|
||||
return poi_ids, rows
|
||||
except Exception as e:
|
||||
print(f"批次处理出错: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
return poi_ids, []
|
||||
|
||||
|
||||
def main():
|
||||
temp_tent = newsetting.All_Setting(DB_HOST, DB_PORT, DB_NAME)
|
||||
task = temp_tent.get_shoppingmalls(
|
||||
f"SELECT DISTINCT poi_id_str FROM productslist_search WHERE workid LIKE '%{workid}%'"
|
||||
)
|
||||
all_poi_ids = [i[0] for i in task]
|
||||
print(f"productslist_search 共有 {len(all_poi_ids)} 个门店")
|
||||
|
||||
poi_batches = [all_poi_ids[i:i + BATCH_SIZE] for i in range(0, len(all_poi_ids), BATCH_SIZE)]
|
||||
print(f"共分成 {len(poi_batches)} 个批次")
|
||||
|
||||
final_tent = newsetting.All_Setting(DB_HOST, DB_PORT, DB_NAME)
|
||||
insert_sql = """
|
||||
insert into ready_list2_copy1 (
|
||||
parent_id, workid, business_code, mt_org_id, poi_id_str, shop_name, address,
|
||||
shipping_fee_tip, min_price_tip, packet_fee_tip, shipping_time,
|
||||
tag1, tag1_name, tag2, tag2_name, tag_type, product_count, allSortedSpuId,
|
||||
product_id, product_name, description, praise_content, month_saled_content,
|
||||
skus_id, spec, actual_price, price, origin_price, activity_price,
|
||||
min_order_count, quota_per_order, dynamic_text, dynamic_url, upccode,
|
||||
want_to_buy_content, praise_rate, picture, promotion_info, tag, activity_tag_id,
|
||||
stock_label, real_stock, skus_count, product_label, vague_picture, create_time, keyword
|
||||
) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)
|
||||
"""
|
||||
|
||||
total_written = 0
|
||||
with multiprocessing.Pool(processes=NUM_PROCESSES, initializer=init_worker) as pool:
|
||||
for handled_ids, res_list in pool.imap_unordered(process_batch_task, poi_batches):
|
||||
if res_list:
|
||||
try:
|
||||
final_tent.write_data(insert_sql, res_list)
|
||||
total_written += len(res_list)
|
||||
print(f'>>> 已写入数据库: {len(res_list)} 条 (累计: {total_written} 条)')
|
||||
del res_list
|
||||
except Exception as e:
|
||||
print(f"写入数据库失败: {e}")
|
||||
else:
|
||||
print(f"本批无数据: {handled_ids}")
|
||||
|
||||
print(f"[{time.strftime('%H:%M:%S')}] 完成,共计 {total_written} 条数据。")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,82 @@
|
||||
import sys
|
||||
|
||||
import pandas
|
||||
|
||||
import newsetting
|
||||
tent2 = newsetting.All_Setting(host='183.6.7.91',port=33016,db='mt_newretail')
|
||||
tent3 = newsetting.All_Setting(host='192.168.5.2',port=3307,db='mt_newretail')
|
||||
|
||||
|
||||
def get_datas(workid,business_type):
|
||||
# sql = f"""
|
||||
# SELECT t1.workid,'{business_type}' AS business_type,t1.wm_poi_id,t1.poi_id_str,t1.shop_name,t1.address,t1.tag1,t1.tag1_name,t1.tag2,t1.tag2_name,t2.product_id,t2.product_name,t2.description,t2.praise_content,t2.month_saled_content,t2.skus_id,t2.spec,t2.actual_price,t2.price,t2.origin_price,t2.activity_price,t2.min_order_count,t2.quota_per_order,t2.dynamic_text,t2.dynamic_url,t2.upccode,t2.want_to_buy_content,t2.praise_rate,t2.picture,t2.promotion_info,t2.tag,t2.activity_tag_id,t2.stock_label,t2.real_stock,t2.skus_count,t2.product_label,t2.getday
|
||||
# FROM (SELECT workid,0 as wm_poi_id,poi_id_str,shop_name,address,tag1,tag1_name,SUBSTRING_INDEX(tag2, '_', 1) as tag2,tag2_name FROM categoryList where workid = '{workid}' and business_code = '{business_code}') as t1
|
||||
# INNER JOIN (SELECT poi_id_str,tag2_id,product_id,product_name,description,praise_content,month_saled_content,skus_id,spec,actual_price,price,origin_price,activity_price,min_order_count,quota_per_order,dynamic_text,dynamic_url,upccode,want_to_buy_content,praise_rate,picture,promotion_info,tag,activity_tag_id,stock_label,real_stock,skus_count,product_label,create_time as getday
|
||||
# FROM productsList where workid = '{workid}') as t2
|
||||
# ON t1.poi_id_str = t2.poi_id_str and ( t1.tag2 = t2.tag )
|
||||
# """
|
||||
# and business_code = 'SURPERMARKET' AND shop_name NOT LIKE '%歪马送酒%'
|
||||
sql2 = f"""
|
||||
SELECT workid, business_code,'-100' as wm_poi_id,poi_id_str,shop_name,address,tag1,tag1_name,tag2,tag2_name,product_id,product_name,description,praise_content,month_saled_content,skus_id,spec,actual_price,price,origin_price,activity_price,min_order_count,quota_per_order,dynamic_text,dynamic_url,upccode,want_to_buy_content,praise_rate,picture,promotion_info,tag,activity_tag_id,stock_label,real_stock,skus_count,product_label,create_time,shipping_fee_tip,min_price_tip,packet_fee_tip,keyword
|
||||
FROM ready_list2_copy1 where workid = '{workid}' order by shop_name
|
||||
"""
|
||||
print(sql2)
|
||||
# input(111111)
|
||||
datas = tent3.get_shoppingmalls(sql2)
|
||||
print(f'{workid}数据总量{len(datas)}')
|
||||
input('自己对一下数据')
|
||||
# day = '2025-08-18'
|
||||
# li = []
|
||||
# for i in datas:
|
||||
# da = i[0:-1]+(day,)
|
||||
# li.append(da)
|
||||
# print(da)
|
||||
# input(f'{workid}数据总量{len(li)},是否写入')
|
||||
# pa = pandas.DataFrame(datas)
|
||||
# pa.to_excel(f'{workid}.xlsx')
|
||||
# for i in range(len(datas)):
|
||||
# start = i*11000数据入flash表_新库.py
|
||||
# end = (i+1)*11000
|
||||
# li2 = datas[start:end]
|
||||
insert_into = """
|
||||
insert into flash_sale_products values (0,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)
|
||||
"""
|
||||
tent2.write_data(insert_into,datas)
|
||||
# pa = pandas.DataFrame(li)
|
||||
# pa.to_excel('HOME20250818_2.xlsx')
|
||||
|
||||
# 17324158028
|
||||
if __name__ == '__main__':
|
||||
# workid = 'APPLE20250828'
|
||||
workid = '20261116'
|
||||
# workid = 'FASHION20250828'
|
||||
# workid = 'APPLE20250902X'
|
||||
# business_type = '3C'
|
||||
# business_code = '3C'
|
||||
get_datas(workid,'business_type')
|
||||
fs = 't1.workid, business_type,t1.wm_poi_id,t1.poi_id_str,t1.shop_name,t1.address,t1.tag1,t1.tag1_name,t1.tag2,t1.tag2_name,t2.product_id,t2.product_name,t2.description,t2.praise_content,t2.month_saled_content,t2.skus_id,t2.spec,t2.actual_price,t2.price,t2.origin_price,t2.activity_price,t2.min_order_count,t2.quota_per_order,t2.dynamic_text,t2.dynamic_url,t2.upccode,t2.want_to_buy_content,t2.praise_rate,t2.picture,t2.promotion_info,t2.tag,t2.activity_tag_id,t2.stock_label,t2.real_stock,t2.skus_count,t2.product_label,t2.getday'
|
||||
print(fs.replace('t1.','').replace('t2.',''))
|
||||
# '''
|
||||
# SELECT
|
||||
# index_id, parent_id, business_code, mt_org_id, poi_id_str,
|
||||
# shop_name, tag1, tag1_name, tag2, tag2_name, tag_type, prox_data, lat, lng
|
||||
# FROM (
|
||||
# SELECT *,
|
||||
# MAX(CASE WHEN tag2_name = '全部' THEN 1 ELSE 0 END)
|
||||
# OVER (PARTITION BY tag1) AS has_quanbu
|
||||
# FROM categorylist
|
||||
# WHERE tag_type IN (1, 27)
|
||||
# AND stype = 27
|
||||
# AND workid = '20260420'
|
||||
# and business_code='chengrenyongpin'
|
||||
# -- 注意:这里去掉 is_ok IS NULL,让窗口函数能看到全部记录
|
||||
# ) t
|
||||
# WHERE
|
||||
# t.is_ok IS NULL -- is_ok 过滤移到外层
|
||||
# AND (
|
||||
# (has_quanbu = 1 AND tag2_name = '全部')
|
||||
# OR
|
||||
# (has_quanbu = 0)
|
||||
# )
|
||||
#
|
||||
# '''
|
||||
@@ -0,0 +1,64 @@
|
||||
from __future__ import annotations
|
||||
|
||||
"""ready_list2_copy1 → flash_sale_products;keyword 为空/NULL 时写成空字符串"""
|
||||
|
||||
import pandas
|
||||
|
||||
import newsetting
|
||||
|
||||
# ==================== 运行参数(改这里) ====================
|
||||
workid = '20260904'
|
||||
# ============================================================
|
||||
|
||||
tent2 = newsetting.All_Setting(host='183.6.7.91', port=33016, db='mt_newretail')
|
||||
tent3 = newsetting.All_Setting(host='192.168.5.2', port=3307, db='mt_newretail')
|
||||
|
||||
|
||||
def get_datas(workid, business_type):
|
||||
# sql = f"""
|
||||
# SELECT t1.workid,'{business_type}' AS business_type,t1.wm_poi_id,t1.poi_id_str,t1.shop_name,t1.address,t1.tag1,t1.tag1_name,t1.tag2,t1.tag2_name,t2.product_id,t2.product_name,t2.description,t2.praise_content,t2.month_saled_content,t2.skus_id,t2.spec,t2.actual_price,t2.price,t2.origin_price,t2.activity_price,t2.min_order_count,t2.quota_per_order,t2.dynamic_text,t2.dynamic_url,t2.upccode,t2.want_to_buy_content,t2.praise_rate,t2.picture,t2.promotion_info,t2.tag,t2.activity_tag_id,t2.stock_label,t2.real_stock,t2.skus_count,t2.product_label,t2.getday
|
||||
# FROM (SELECT workid,0 as wm_poi_id,poi_id_str,shop_name,address,tag1,tag1_name,SUBSTRING_INDEX(tag2, '_', 1) as tag2,tag2_name FROM categoryList where workid = '{workid}' and business_code = '{business_code}') as t1
|
||||
# INNER JOIN (SELECT poi_id_str,tag2_id,product_id,product_name,description,praise_content,month_saled_content,skus_id,spec,actual_price,price,origin_price,activity_price,min_order_count,quota_per_order,dynamic_text,dynamic_url,upccode,want_to_buy_content,praise_rate,picture,promotion_info,tag,activity_tag_id,stock_label,real_stock,skus_count,product_label,create_time as getday
|
||||
# FROM productsList where workid = '{workid}') as t2
|
||||
# ON t1.poi_id_str = t2.poi_id_str and ( t1.tag2 = t2.tag )
|
||||
# """
|
||||
# and business_code = 'SURPERMARKET' AND shop_name NOT LIKE '%歪马送酒%'
|
||||
sql2 = f"""
|
||||
SELECT workid, business_code,'-100' as wm_poi_id,poi_id_str,shop_name,address,tag1,tag1_name,tag2,tag2_name,product_id,product_name,description,praise_content,month_saled_content,skus_id,spec,actual_price,price,origin_price,activity_price,min_order_count,quota_per_order,dynamic_text,dynamic_url,upccode,want_to_buy_content,praise_rate,picture,promotion_info,tag,activity_tag_id,stock_label,real_stock,skus_count,product_label,create_time,shipping_fee_tip,min_price_tip,packet_fee_tip,IFNULL(keyword, '') AS keyword
|
||||
FROM ready_list2_copy1 where workid = '{workid}' order by shop_name
|
||||
"""
|
||||
print(sql2)
|
||||
# input(111111)
|
||||
datas = tent3.get_shoppingmalls(sql2)
|
||||
print(f'{workid}数据总量{len(datas)}')
|
||||
input('自己对一下数据')
|
||||
# day = '2025-08-18'
|
||||
# li = []
|
||||
# for i in datas:
|
||||
# da = i[0:-1]+(day,)
|
||||
# li.append(da)
|
||||
# print(da)
|
||||
# input(f'{workid}数据总量{len(li)},是否写入')
|
||||
# pa = pandas.DataFrame(datas)
|
||||
# pa.to_excel(f'{workid}.xlsx')
|
||||
# for i in range(len(datas)):
|
||||
# start = i*11000数据入flash表_新库.py
|
||||
# end = (i+1)*11000
|
||||
# li2 = datas[start:end]
|
||||
insert_into = """
|
||||
insert into flash_sale_products values (0,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)
|
||||
"""
|
||||
tent2.write_data(insert_into, datas)
|
||||
# pa = pandas.DataFrame(li)
|
||||
# pa.to_excel('HOME20250818_2.xlsx')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# workid = 'APPLE20250828'
|
||||
# workid = 'FASHION20250828'
|
||||
# workid = 'APPLE20250902X'
|
||||
# business_type = '3C'
|
||||
# business_code = '3C'
|
||||
get_datas(workid, 'business_type')
|
||||
fs = 't1.workid, business_type,t1.wm_poi_id,t1.poi_id_str,t1.shop_name,t1.address,t1.tag1,t1.tag1_name,t1.tag2,t1.tag2_name,t2.product_id,t2.product_name,t2.description,t2.praise_content,t2.month_saled_content,t2.skus_id,t2.spec,t2.actual_price,t2.price,t2.origin_price,t2.activity_price,t2.min_order_count,t2.quota_per_order,t2.dynamic_text,t2.dynamic_url,t2.upccode,t2.want_to_buy_content,t2.praise_rate,t2.picture,t2.promotion_info,t2.tag,t2.activity_tag_id,t2.stock_label,t2.real_stock,t2.skus_count,t2.product_label,t2.getday'
|
||||
print(fs.replace('t1.', '').replace('t2.', ''))
|
||||
@@ -0,0 +1,83 @@
|
||||
import sys
|
||||
|
||||
import pandas
|
||||
|
||||
import newsetting
|
||||
tent2 = newsetting.All_Setting(host='183.6.7.91',port=33016,db='mt_newretail')
|
||||
tent3 = newsetting.All_Setting(host='192.168.5.2',port=3307,db='mt_newretail')
|
||||
|
||||
|
||||
def get_datas(workid,business_type):
|
||||
# sql = f"""
|
||||
# SELECT t1.workid,'{business_type}' AS business_type,t1.wm_poi_id,t1.poi_id_str,t1.shop_name,t1.address,t1.tag1,t1.tag1_name,t1.tag2,t1.tag2_name,t2.product_id,t2.product_name,t2.description,t2.praise_content,t2.month_saled_content,t2.skus_id,t2.spec,t2.actual_price,t2.price,t2.origin_price,t2.activity_price,t2.min_order_count,t2.quota_per_order,t2.dynamic_text,t2.dynamic_url,t2.upccode,t2.want_to_buy_content,t2.praise_rate,t2.picture,t2.promotion_info,t2.tag,t2.activity_tag_id,t2.stock_label,t2.real_stock,t2.skus_count,t2.product_label,t2.getday
|
||||
# FROM (SELECT workid,0 as wm_poi_id,poi_id_str,shop_name,address,tag1,tag1_name,SUBSTRING_INDEX(tag2, '_', 1) as tag2,tag2_name FROM categoryList where workid = '{workid}' and business_code = '{business_code}') as t1
|
||||
# INNER JOIN (SELECT poi_id_str,tag2_id,product_id,product_name,description,praise_content,month_saled_content,skus_id,spec,actual_price,price,origin_price,activity_price,min_order_count,quota_per_order,dynamic_text,dynamic_url,upccode,want_to_buy_content,praise_rate,picture,promotion_info,tag,activity_tag_id,stock_label,real_stock,skus_count,product_label,create_time as getday
|
||||
# FROM productsList where workid = '{workid}') as t2
|
||||
# ON t1.poi_id_str = t2.poi_id_str and ( t1.tag2 = t2.tag )
|
||||
# """
|
||||
# and business_code = 'SURPERMARKET' AND shop_name NOT LIKE '%歪马送酒%'
|
||||
# 列顺序与原脚本一致,只把第 2 列 business_code 里的 SURPERMARKET1/2 收成 SURPERMARKET
|
||||
sql2 = f"""
|
||||
SELECT workid, CASE WHEN business_code IN ('SURPERMARKET1', 'SURPERMARKET2') THEN 'SURPERMARKET' ELSE business_code END AS business_code,'-100' as wm_poi_id,poi_id_str,shop_name,address,tag1,tag1_name,tag2,tag2_name,product_id,product_name,description,praise_content,month_saled_content,skus_id,spec,actual_price,price,origin_price,activity_price,min_order_count,quota_per_order,dynamic_text,dynamic_url,upccode,want_to_buy_content,praise_rate,picture,promotion_info,tag,activity_tag_id,stock_label,real_stock,skus_count,product_label,create_time,shipping_fee_tip,min_price_tip,packet_fee_tip,keyword
|
||||
FROM ready_list2_copy1 where workid = '{workid}' order by shop_name
|
||||
"""
|
||||
print(sql2)
|
||||
# input(111111)
|
||||
datas = tent3.get_shoppingmalls(sql2)
|
||||
print(f'{workid}数据总量{len(datas)}')
|
||||
input('自己对一下数据')
|
||||
# day = '2025-08-18'
|
||||
# li = []
|
||||
# for i in datas:
|
||||
# da = i[0:-1]+(day,)
|
||||
# li.append(da)
|
||||
# print(da)
|
||||
# input(f'{workid}数据总量{len(li)},是否写入')
|
||||
# pa = pandas.DataFrame(datas)
|
||||
# pa.to_excel(f'{workid}.xlsx')
|
||||
# for i in range(len(datas)):
|
||||
# start = i*11000数据入flash表_新库.py
|
||||
# end = (i+1)*11000
|
||||
# li2 = datas[start:end]
|
||||
insert_into = """
|
||||
insert into flash_sale_products values (0,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)
|
||||
"""
|
||||
tent2.write_data(insert_into,datas)
|
||||
# pa = pandas.DataFrame(li)
|
||||
# pa.to_excel('HOME20250818_2.xlsx')
|
||||
|
||||
# 17324158028
|
||||
if __name__ == '__main__':
|
||||
# workid = 'APPLE20250828'
|
||||
workid = '20261019'
|
||||
# workid = 'FASHION20250828'
|
||||
# workid = 'APPLE20250902X'
|
||||
# business_type = '3C'
|
||||
# business_code = '3C'
|
||||
get_datas(workid,'business_type')
|
||||
fs = 't1.workid, business_type,t1.wm_poi_id,t1.poi_id_str,t1.shop_name,t1.address,t1.tag1,t1.tag1_name,t1.tag2,t1.tag2_name,t2.product_id,t2.product_name,t2.description,t2.praise_content,t2.month_saled_content,t2.skus_id,t2.spec,t2.actual_price,t2.price,t2.origin_price,t2.activity_price,t2.min_order_count,t2.quota_per_order,t2.dynamic_text,t2.dynamic_url,t2.upccode,t2.want_to_buy_content,t2.praise_rate,t2.picture,t2.promotion_info,t2.tag,t2.activity_tag_id,t2.stock_label,t2.real_stock,t2.skus_count,t2.product_label,t2.getday'
|
||||
print(fs.replace('t1.','').replace('t2.',''))
|
||||
# '''
|
||||
# SELECT
|
||||
# index_id, parent_id, business_code, mt_org_id, poi_id_str,
|
||||
# shop_name, tag1, tag1_name, tag2, tag2_name, tag_type, prox_data, lat, lng
|
||||
# FROM (
|
||||
# SELECT *,
|
||||
# MAX(CASE WHEN tag2_name = '全部' THEN 1 ELSE 0 END)
|
||||
# OVER (PARTITION BY tag1) AS has_quanbu
|
||||
# FROM categorylist
|
||||
# WHERE tag_type IN (1, 27)
|
||||
# AND stype = 27
|
||||
# AND workid = '20260420'
|
||||
# and business_code='chengrenyongpin'
|
||||
# -- 注意:这里去掉 is_ok IS NULL,让窗口函数能看到全部记录
|
||||
# ) t
|
||||
# WHERE
|
||||
# t.is_ok IS NULL -- is_ok 过滤移到外层
|
||||
# AND (
|
||||
# (has_quanbu = 1 AND tag2_name = '全部')
|
||||
# OR
|
||||
# (has_quanbu = 0)
|
||||
# )
|
||||
#
|
||||
# '''
|
||||
Reference in New Issue
Block a user