更新文件说明
This commit is contained in:
@@ -512,7 +512,7 @@ VALUES (%s, %s, %s, %s, %s, %s, %s)
|
||||
SELECT `id`,json_data,prox,city,mt_traceid FROM `hotel_hd` WHERE title LIKE '%美团酒店详情%' and is_ok is NULL and current_count<10;
|
||||
'''
|
||||
sql = '''
|
||||
SELECT `id`,json_data,prox,city,mt_traceid,dfpid FROM `hotel_hd` WHERE title LIKE '%美团酒店详情%' and is_ok is NULL;
|
||||
SELECT `id`,json_data,prox,city,mt_traceid,dfpid FROM `hotel_hd` WHERE title LIKE '%美团酒店详情%' and is_ok is NULL and city is not null;
|
||||
'''
|
||||
# sql = '''
|
||||
# SELECT `id`,json_data,prox,city,mt_traceid FROM `hotel_hd` WHERE title LIKE '%美团酒店详情%' and ((is_ok != 403 and is_ok != 418 and is_ok != 401) or is_ok is null) and id=12635
|
||||
@@ -522,6 +522,10 @@ VALUES (%s, %s, %s, %s, %s, %s, %s)
|
||||
|
||||
def run_one(self, items):
|
||||
items = list(items)
|
||||
if not items:
|
||||
# 空池保护:没有可跑的包就不要去随机城市要任务(避免刷“拿任务失败”)
|
||||
print('没有可用包,跳过本轮')
|
||||
return
|
||||
# 埋点兜底:拿任务失败时还没走 item 选择,先用首条记录账号身份(不影响主流程)
|
||||
_fallback = items[0] if items else None
|
||||
_fallback_id = _fallback[0] if _fallback else None
|
||||
@@ -559,14 +563,7 @@ VALUES (%s, %s, %s, %s, %s, %s, %s)
|
||||
item = j
|
||||
break
|
||||
if not item:
|
||||
if none_city_item_list:
|
||||
item = none_city_item_list[0]
|
||||
else:
|
||||
# 城市不匹配:任务城市在可用包里找不到对应账号 → 这轮跑不了,标记后跳过
|
||||
print(f"没有与任务城市 {cityName} 匹配的包,跳过")
|
||||
self.mark_city_mismatch(task_city, _fallback_id, _fallback_dfpid,
|
||||
f"任务城市 {cityName} 没有匹配的包")
|
||||
return -1
|
||||
item = none_city_item_list[0]
|
||||
# 跑单条抓包:解析 headers -> 绑定城市/IP -> 分接口请求 -> 回写状态
|
||||
ind, hd, prox, city, mt_traceid, dfpid = item
|
||||
# 埋点:领到任务(账号 + 绑定城市 + 目标城市)
|
||||
@@ -592,30 +589,14 @@ VALUES (%s, %s, %s, %s, %s, %s, %s)
|
||||
matched = [p for p in self.proxy_list if p[1] == city]
|
||||
if not matched:
|
||||
print(f"城市 {city} 在代理池无IP,跳过")
|
||||
self.mark_city_mismatch(city, ind, dfpid, f"城市 {city} 在代理池没有可用 IP")
|
||||
return
|
||||
self.proxy = json.loads(matched[0][0])
|
||||
self.bound_city = city
|
||||
elif not city and prox:
|
||||
# 有IP没城市:反查这个 IP 属于哪个城市
|
||||
matched = [p for p in self.proxy_list if p[0] == prox]
|
||||
if not matched:
|
||||
print(f"ID={ind} 有IP但反查不到城市,跳过")
|
||||
self.mark_city_mismatch(city or getattr(self, "bound_city", None), ind, dfpid,
|
||||
"代理 IP 反查不到城市")
|
||||
return
|
||||
self.bound_city = matched[0][1]
|
||||
self.proxy = json.loads(prox)
|
||||
city = self.bound_city
|
||||
else:
|
||||
# 全新包:随机拿一个 IP,并把城市绑定回 hotel_hd
|
||||
# pick = self.proxy_list[random.randint(0, len(self.proxy_list) - 1)]
|
||||
for pick in self.proxy_list:
|
||||
if pick[1] == cityName.replace('市',''):
|
||||
self.proxy = json.loads(pick[0])
|
||||
self.bound_city = pick[1]
|
||||
break
|
||||
city = self.bound_city
|
||||
# 没有城市的包(新包 / 只有代理没城市):不再自动绑定城市,
|
||||
# 一律等看板「添加城市」之后再跑
|
||||
print(f"ID={ind} 还没有绑定城市,跳过:请先在看看板里添加城市")
|
||||
return
|
||||
|
||||
print(f"本次使用: 城市={self.bound_city}, proxy={self.proxy}")
|
||||
|
||||
@@ -624,15 +605,10 @@ VALUES (%s, %s, %s, %s, %s, %s, %s)
|
||||
if '/hotel/core/router/shelf' in new_url:
|
||||
result = self.run_shelf(new_url, params, headers, data, None, task)
|
||||
if result == -1:
|
||||
# 绑定城市查不到 cityId / 没有坐标 → 城市不匹配,这包跑不了
|
||||
_c = getattr(self, "bound_city", None) or city
|
||||
self.mark_city_mismatch(_c, ind, dfpid, f"城市 {_c} 缺少 cityId/坐标")
|
||||
return -1
|
||||
elif '/productapi/v3/prepayList' in new_url:
|
||||
result = self.run_prepayList(new_url, params, headers, None, task)
|
||||
if result == -1:
|
||||
_c = getattr(self, "bound_city", None) or city
|
||||
self.mark_city_mismatch(_c, ind, dfpid, f"城市 {_c} 缺少 cityId/坐标")
|
||||
return -1
|
||||
else:
|
||||
print(f"未知接口,跳过: {new_url}")
|
||||
@@ -658,28 +634,6 @@ VALUES (%s, %s, %s, %s, %s, %s, %s)
|
||||
insight.log_exception(ind, dfpid, task_city, e, code=is_ok)
|
||||
self.update_headers(is_ok, ind, city, None)
|
||||
|
||||
def mark_package_failed(self, hd_id, reason=""):
|
||||
"""把单个包标记为 is_ok=0(城市不匹配 / 这包跑不了)。失败只打印,不影响主流程。"""
|
||||
if not hd_id:
|
||||
return
|
||||
try:
|
||||
tent2.update_data(f"UPDATE hotel_hd SET is_ok=0 WHERE `id`={int(hd_id)}")
|
||||
print(f"包 #{hd_id} {reason} → is_ok=0")
|
||||
except Exception as e:
|
||||
print(f"标记包失败(不影响主流程): {type(e).__name__}: {e}")
|
||||
|
||||
def mark_city_mismatch(self, city, hd_id=None, dfpid=None, reason="城市不匹配"):
|
||||
"""城市不匹配导致这轮跑不了:①记一次拿任务失败(看板“拿任务失败城市”)②该包 is_ok=0。
|
||||
|
||||
两个动作各自兜底,任何异常都不能影响采集主流程。
|
||||
"""
|
||||
if city:
|
||||
try:
|
||||
insight.log_fetch_empty(hd_id, dfpid, city, city, None, note=reason)
|
||||
except Exception:
|
||||
pass
|
||||
self.mark_package_failed(hd_id, f"{reason}(城市 {city or '未知'})")
|
||||
|
||||
def mark_city_failed(self, city):
|
||||
"""拿任务失败时,把该城市下所有可用包(is_ok IS NULL)标记为 0。
|
||||
|
||||
@@ -770,6 +724,12 @@ if __name__ == '__main__':
|
||||
for i in range(1000):
|
||||
ht = hotel_run()
|
||||
items = ht.get_headers()
|
||||
if not items:
|
||||
# 空池(没有 is_ok IS NULL 且已绑定城市的包):不要随机挑代理城市去要任务,
|
||||
# 否则每轮都会给一个不相干的城市记一条“拿任务失败”,几十秒就能刷满 39 城。
|
||||
print('没有可用包(is_ok IS NULL 且已绑定城市),30 秒后重试;要停止请点看板停止 / Ctrl+C')
|
||||
time.sleep(30)
|
||||
continue
|
||||
ht.run_one(items)
|
||||
time.sleep(random.randint(2, 5))
|
||||
# run2()
|
||||
|
||||
Reference in New Issue
Block a user