104 lines
4.1 KiB
Python
104 lines
4.1 KiB
Python
"""店铺入库去新客版:优惠列表不写闪购新客专享红包,其他券和满减照常。原 run.py 不动。"""
|
|
import datetime
|
|
import json
|
|
import random
|
|
import sys
|
|
import time
|
|
|
|
sys.path.append('../../setting')
|
|
import newsetting as ten
|
|
import get_food_去新客 as get_food
|
|
import reqFOOD2
|
|
|
|
# ==================== 运行参数(改这里) ====================
|
|
REQUEST_INTERVAL = 2.0 # 每个 poi 基础间隔(秒)
|
|
INTERVAL_JITTER = 1.0 # 额外随机 0~N 秒,减轻固定节奏指纹
|
|
CONTINUE_ON_666 = True # 商家无效/无商品时继续下一个 poi,不停包
|
|
# ============================================================
|
|
|
|
tent2 = ten.All_Setting(host='192.168.5.2', port=3307, db='mt_newretail')
|
|
tent3 = ten.All_Setting(host='192.168.5.2', port=3307, db='headers_project')
|
|
|
|
|
|
def _sleep_interval():
|
|
if REQUEST_INTERVAL <= 0 and INTERVAL_JITTER <= 0:
|
|
return
|
|
delay = max(0.0, REQUEST_INTERVAL) + random.uniform(0, max(0.0, INTERVAL_JITTER))
|
|
time.sleep(delay)
|
|
|
|
|
|
def run(workid, headers):
|
|
sql = f""" select `index`,poi_id_str,business_code,prox,lat,lng
|
|
FROM project_input where is_ok is null and `index`>4072 and workid like '%{workid}%'"""
|
|
a1 = tent2.get_shoppingmalls(sql)
|
|
pkg_id = headers[0]
|
|
headersdata = headers[3]
|
|
print(f'[包] id={pkg_id} backend={reqFOOD2.BACKEND} 待跑={len(a1)}')
|
|
print(a1)
|
|
print(len(a1))
|
|
# 换包重建连接,避免上一个包的代理/TLS 连接池串过来
|
|
reqFOOD2.reset_mt_session()
|
|
ok_count = 0
|
|
for i in a1[:]:
|
|
index, poiid, business_code, prox, lat, lng = i
|
|
if isinstance(prox, dict):
|
|
prox2 = prox
|
|
elif isinstance(prox, str):
|
|
prox2 = json.loads(prox)
|
|
else:
|
|
prox2 = {'http': None, 'https': None}
|
|
# input(132456)
|
|
reqs = reqFOOD2.req_food('-100', poiid, prox2, lat, lng, headersdata)
|
|
if reqs == 666:
|
|
update_sql = f"""
|
|
update project_input set is_ok = 666 where `index` = {index}
|
|
"""
|
|
tent2.update_data(update_sql)
|
|
if CONTINUE_ON_666:
|
|
_sleep_interval()
|
|
continue
|
|
print(f'[停包] id={pkg_id} 666 且 CONTINUE_ON_666=False,已成功={ok_count}')
|
|
break
|
|
if isinstance(reqs, tuple) and reqs[0] == 418:
|
|
sql = '''
|
|
update market_food_headers set is_ok=%s,json_data=%s where `id`=%s
|
|
'''
|
|
tent3.write_data(sql, ((reqs[0], reqs[1], pkg_id),))
|
|
print(f'[死号] id={pkg_id} yoda/418,本包已成功={ok_count},换下一包')
|
|
break
|
|
if isinstance(reqs, int):
|
|
sql = f'''
|
|
update market_food_headers set is_ok={reqs} where id='{pkg_id}'
|
|
'''
|
|
tent3.update_data(sql)
|
|
print(f'[死号] id={pkg_id} is_ok={reqs},本包已成功={ok_count},换下一包')
|
|
break
|
|
sql = f'''
|
|
update market_food_headers set req_count=req_count+1 where id='{pkg_id}'
|
|
'''
|
|
tent3.update_data(sql)
|
|
get_food.rec_food(reqs, workid, business_code, poiid, prox, lat, lng, parent_id=1)
|
|
update_sql = f"""
|
|
update project_input set is_ok = 1 where `index` = {index}
|
|
"""
|
|
tent2.update_data(update_sql)
|
|
ok_count += 1
|
|
print(f'[成功] pkg={pkg_id} poi={poiid} 本包累计={ok_count}')
|
|
_sleep_interval()
|
|
# 22774299, 10827996
|
|
reqFOOD2.reset_mt_session()
|
|
print(f'[包结束] id={pkg_id} 本包成功={ok_count}')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
sql = '''
|
|
select * from market_food_headers where is_ok is null and title like '%便利店%' and id >= 0
|
|
'''
|
|
rt = tent3.get_shoppingmalls(sql)
|
|
format_today = str(datetime.date.today()).replace('-', '')
|
|
# format_today ='20261026'
|
|
print(f'[启动] 可用包={len(rt)} backend={reqFOOD2.BACKEND} interval={REQUEST_INTERVAL}+0~{INTERVAL_JITTER}s')
|
|
for j in rt[:]:
|
|
run(workid=f'{format_today}', headers=j)
|
|
# {"http": "http://0uql:0uqlp@183.131.35.75:21633", "https": "http://0uql:0uqlp@183.131.35.75:21633"}
|
|
# 24414891,109201428 |