chore: snapshot local changes

This commit is contained in:
2026-05-20 16:06:17 +08:00
parent 13925e5070
commit 8bfe38e9dc
21 changed files with 20723 additions and 153 deletions
+160 -67
View File
@@ -9,6 +9,7 @@ import pymysql
from curl_cffi import requests
import json
from newsetting import All_Setting
import redis_lock_get_data
tent2 = All_Setting(host="183.6.7.91", port=33016, db="tk_test")
tent3 = All_Setting(host="183.6.7.91", port=33016, db="headers_project")
@@ -124,14 +125,14 @@ def one_(id1, id2, num, shop_id, hd,prox, one_all_num=None):
timestamp = int(time.time())
timestamp_ms = int(time.time())*1000
params = dict(re.findall(r"([^&=]+)=([^&]*)", query))
# params.update({"app_trace":params['uuid']+str(timestamp)})
params.update({"app_trace":params['uuid']+str(timestamp_ms)})
data = hd_data[2]
params.update({"poi": str(shop_id)})
params.update({"stockPois": str(shop_id)})
params.update({"app_trace":params['uuid']+str(timestamp)})
# params.update({"app_trace":params['uuid']+str(timestamp_ms)})
url1 = f"https://mall.meituan.com/api/c/poi/{str(shop_id)}/sku/list/category/v8?"
url1 = url1 + get_Datatext(params)
data.update({"poiId": shop_id})
data.update({"poiId": str(shop_id)})
data.update({"firstCategoryId": id1})
data.update({"categoryId": id2})
data["secondCategoryInfo"].update({"secondCategoryId": id2})
@@ -142,14 +143,14 @@ def one_(id1, id2, num, shop_id, hd,prox, one_all_num=None):
data["pageInfo"].update({"total": 150})
data["secondCategoryInfo"].update({"skuCount": 150})
else:
data["pageInfo"].update({"total": 300})
data["secondCategoryInfo"].update({"skuCount": 300})
data["pageInfo"].update({"total": 500})
data["secondCategoryInfo"].update({"skuCount": 500})
data["pageInfo"].update({"prePageOffset": max(0,(num - 2)) * 20})
data["pageInfo"].update({"offset": (num - 1) * 20})
data["pageInfo"].update({"nextPageOffset": (num - 1) * 20})
data.update({"cacheKey": f'cate_{shop_id}_{params["userid"]}_{id1}_1'})
data.update({"type": '1'})
data["secondCategoryInfo"].update({"type": '1'})
# data.update({"type": '1'})
# data["secondCategoryInfo"].update({"type": '1'})
data.update({"type": '0'})
data["secondCategoryInfo"].update({"type": '0'})
@@ -175,14 +176,16 @@ def one_(id1, id2, num, shop_id, hd,prox, one_all_num=None):
openId = headers['openId']
# headers['mtgsig'] = get_sign_new(url1, data1, dfpid, mtg_origin)
headers['mtgsig'] = get_sign_new1(url1, data1, dfpid, mtg_origin, openId)
headers["Content-Length"] = str(len(data1))
headers["Content-Length"] = len(data1)
response = requests.post(url1, headers=headers, data=data1, proxies=prox, verify=False)
# response = requests.post(url1, headers=headers, data=data1,verify=False)
print(response.text[:])
print(len(data1))
input(56123)
return response, shop_id
def 获取小象task():
# get_hotel
datas = redis_lock_get_data.get_hotel()
return datas
# 每个分类都跑一次拿总数(自带20)
def all_one(shop_id, workid, hd, work_queue):
@@ -198,6 +201,7 @@ def all_one(shop_id, workid, hd, work_queue):
prox = SHOP_PROX[shop_id]
except:
prox = list(SHOP_PROX.values())[0]
prox = list(SHOP_PROX.values())[random.randint(0, len(SHOP_PROX) - 1)]
req, shop_id = one_(i[2], i[4], num, shop_id, hd, prox)
if "您的网络好像不太给力" in req.text:
update_headers(418, hd_id)
@@ -224,14 +228,14 @@ def all_one(shop_id, workid, hd, work_queue):
# )
# tent2.update_data(update_sql)
return 0
for jj in req["data"]["contents"][0]["subModule"]["contents"]:
one_price = jj["lxInfo"].get("sale_price")
if one_price:
if one_price == "?":
update_headers(406, hd_id)
return 406
else:
break
for jj in req["data"]["contents"][0]["subModule"]["contents"]:
one_price = jj["lxInfo"].get("sale_price")
if one_price:
if one_price == "?":
update_headers(406, hd_id)
return 406
else:
break
tent2.write_data_one(
"""
INSERT INTO category_detail_log
@@ -240,11 +244,9 @@ def all_one(shop_id, workid, hd, work_queue):
""",
(shop_id, num, i[2], i[4], json.dumps(req, ensure_ascii=False), workid),
)
# tent2.update_data(update_sql)
update_sql = f"""
UPDATE category_detail
SET all_num = {int(req["data"]["pageInfo"]["lastPageOffset"])},
now_num = {num * 20},
is_ok = 1,
one_all_num = {int(req["data"]["pageInfo"]["total"])}
WHERE `id` = {detail_id}
@@ -267,6 +269,8 @@ def one_all(workid, hd, work_queue):
prox = SHOP_PROX[shop_id]
except:
prox = list(SHOP_PROX.values())[0]
if one_all_num is None:
one_all_num = 400
all_num = math.ceil(one_all_num / 20) + 1
now_num = math.ceil(now_num / 20) + 1
for k in range(now_num, all_num):
@@ -317,6 +321,80 @@ def one_all(workid, hd, work_queue):
return 1
# 一个分类跑完
def one_all2(workid, hd, work_queue):
import math
item_list = 获取小象task()
print(item_list)
for item in item_list:
detail_id, shop_id, one_id, two_id, one_all_num, now_num,workid = item
try:
prox = SHOP_PROX[shop_id]
except:
prox = list(SHOP_PROX.values())[0]
if one_all_num is None:
one_all_num = 400
prox = list(SHOP_PROX.values())[random.randint(0, len(SHOP_PROX) - 1)]
all_num = math.ceil(one_all_num / 20) + 1
now_num = math.ceil(now_num / 20) + 1
for k in range(now_num, all_num):
print(f"now_num是{k}")
hd_id = hd[0]
req, shop_id = one_(one_id, two_id, k, shop_id, hd,prox, one_all_num)
if "您的网络好像不太给力" in req.text:
update_headers(418, hd_id)
return 418
try:
req = req.json()
except Exception as e:
print(f'出问题的情况是{e}')
if "Expecting value: line 1 column 1 (char 0)" in str(e) or '403 Forbidden' in str(e) or 'unexpected character: line 1 column 1 (char 0)' in str(e):
update_headers(403, hd_id)
return 403
if req["data"] == {}:
return 1
for jj in req["data"]["contents"][0]["subModule"]["contents"]:
one_price = jj["lxInfo"].get("sale_price")
if one_price:
if one_price == "?":
update_headers(406, hd_id)
return 406
else:
break
tent2.write_data_one(
"""
INSERT INTO category_detail_log
(shop_id,category_detail_id, one_id, two_id, req_json,work_id)
VALUES (%s,%s, %s, %s, %s,%s)
""",
(shop_id, k, one_id, two_id, json.dumps(req, ensure_ascii=False), workid),
)
update_sql = f"""
UPDATE category_detail
SET all_num = {int(req["data"]["pageInfo"]["lastPageOffset"])},
now_num = {k * 20},
is_ok = 1,
one_all_num = {int(req["data"]["pageInfo"]["total"])}
WHERE `id` = {detail_id}
"""
tent2.update_data(update_sql)
nextPageOffset = int(req["data"]["pageInfo"]["nextPageOffset"])
update_headers(1, hd_id)
if nextPageOffset == -1:
update_sql = f"""
UPDATE category_detail
SET all_num = {int(req["data"]["pageInfo"]["lastPageOffset"])},
now_num = {k * 20},
is_ok2 = 1,
one_all_num = {int(req["data"]["pageInfo"]["total"])}
WHERE `id` = {detail_id}
"""
tent2.update_data(update_sql)
break
return 1
# 拿到请求头部
def get_hds():
sql3 = f"""
@@ -330,16 +408,18 @@ def worker_allone(shop_id, workid, hd, work_queue):
while not work_queue.empty():
if all_one(shop_id, workid, hd, work_queue) != 1:
break
time.sleep(random.randint(2, 4))
# time.sleep(random.randint(2, 4))
# all_one(shop_id, workid, hd, work_queue)
def worker(workid, hd, work_queue):
while not work_queue.empty():
if one_all(workid, hd, work_queue) !=1:
result = one_all(workid, hd, work_queue)
print(result)
if result !=1:
break
time.sleep(random.randint(3, 15))
# time.sleep(random.randint(3, 15))
# one_all(workid, hd, work_queue)
@@ -350,7 +430,7 @@ def run_all_one(hds, workid, shop_id_list, one_ids):
sql_all_one_pending = f"""
select * FROM category_detail
where one_id in ({",".join(map(str, one_ids))})
and now_num = 0
and is_ok is null
and shop_id='{shop_id}' and work_id='{workid}'
"""
items = tent2.get_shoppingmalls(sql_all_one_pending)
@@ -358,49 +438,59 @@ def run_all_one(hds, workid, shop_id_list, one_ids):
item_list.append(item)
work_queue_allone.put(item)
print(item_list)
# with ThreadPoolExecutor(max_workers=5) as pool:
# for hd in hds:
# pool.submit(worker_allone, 0, workid, hd, work_queue_allone)
for hd in hds:
worker_allone(0,workid,hd,work_queue_allone)
with ThreadPoolExecutor(max_workers=10) as pool:
for hd in hds:
pool.submit(worker_allone, 0, workid, hd, work_queue_allone)
# for hd in hds:
# worker_allone(0,workid,hd,work_queue_allone)
def run_one_all(hds, workid, shop_id_list):
def run_one_all(hds, workid, shop_id_list, one_ids):
work_queue = queue.Queue()
shop_ids_sql = ",".join(map(str, shop_id_list))
sql_all_pending = f"""
select id,shop_id,one_id,two_id,one_all_num,now_num FROM category_detail where one_all_num > now_num and work_id='{workid}' and shop_id in ({shop_ids_sql})
select id,shop_id,one_id,two_id,one_all_num,now_num FROM category_detail where one_id in ({",".join(map(str, one_ids))}) and work_id='{workid}' and shop_id in ({shop_ids_sql}) and is_ok2 is null and (one_all_num is null or (one_all_num > now_num))
"""
print(sql_all_pending)
# input(45623)
items = tent2.get_shoppingmalls(sql_all_pending)
for item in items[:]:
work_queue.put(item)
with ThreadPoolExecutor(max_workers=5) as pool:
for hd in hds:
pool.submit(worker, workid, hd, work_queue)
# worker(workid, hds[0], work_queue)
# with ThreadPoolExecutor(max_workers=5) as pool:
# for hd in hds:
# pool.submit(worker, workid, hd, work_queue)
for hd in hds:
worker(workid, hd, work_queue)
def run_one_all2(hds, workid, shop_id_list):
# with ThreadPoolExecutor(max_workers=10) as pool:
# for hd in hds:
# pool.submit(one_all2, workid, hd, '')
# for hd in hds:
# one_all2(workid, hd, '')
one_all2(workid, hds[0], '')
SHOP_ID_LIST = [
10000439,
10000900,
10000880,
10000665,
10000839,
10000519,
10001060,
10000163,
10000952,
10000956,
10001084,
10001075,
10001107,
10001195,
10001222,
10001400,
10001506,
10001575,
# 10000439,
# 10000900,
# 10000880,
# 10000665,
# 10000839,
# 10000519,
# 10001060,
# 10000163,
# 10000952,
# 10000956,
# 10001084,
# 10001075,
# 10001107,
# 10001195,
# 10001222,
# 10001400,
# 10001506,
# 10001575,
10000745,
]
SHOP_IDS_ENV = "ELEPHANT_SHOP_IDS"
@@ -425,18 +515,20 @@ city_dict = {
10001575: "温州",
}
ONE_IDS = [
40532,
40488,
40581,
40652,
40461,
40916,
40478,
40455,
# 40532,
# 40488,
# 40581,
# 40652,
# 40461,
# 40916,
# 40478,
# 40455,
# 40485,
# 40472,
# 49207,
# 42793,
40485,
40472,
49207,
42793,
]
CITY_PROX = {}
SHOP_PROX = {}
@@ -470,8 +562,9 @@ def main():
print(hds)
workid = get_workid()
shop_id_list = get_shop_id_list()
run_all_one(hds, workid, shop_id_list, ONE_IDS)
# run_one_all(hds, workid, shop_id_list)
# run_all_one(hds, workid, shop_id_list, ONE_IDS)
run_one_all(hds, workid, shop_id_list, ONE_IDS)
# run_one_all2(hds, workid, shop_id_list)
if __name__ == "__main__":
get_prox()