fix: 修改代理获取逻辑以使用新的 fetch_proxies2 函数并优化打印信息
This commit is contained in:
parent
e4ae20acb4
commit
8e0c99284b
1
DB.py
1
DB.py
@ -162,6 +162,7 @@ class DBVidcon:
|
|||||||
data.setdefault("a_id", 0)
|
data.setdefault("a_id", 0)
|
||||||
data.setdefault("history_status", "")
|
data.setdefault("history_status", "")
|
||||||
data.setdefault("is_piracy", 3)
|
data.setdefault("is_piracy", 3)
|
||||||
|
data.setdefault("is_repeat", 3)
|
||||||
data["sort"] = data.get("index", 0)
|
data["sort"] = data.get("index", 0)
|
||||||
|
|
||||||
max_retries = 1 # 除了第一次外,再重试一次
|
max_retries = 1 # 除了第一次外,再重试一次
|
||||||
|
2
main.py
2
main.py
@ -569,7 +569,7 @@ def get_searchInfo(keyword):
|
|||||||
print('resinfo :', len(resinfo))
|
print('resinfo :', len(resinfo))
|
||||||
except Exception:
|
except Exception:
|
||||||
resinfo = []
|
resinfo = []
|
||||||
print(response.text)
|
print("[搜索接口]", response.text)
|
||||||
print("返回字段解析错误!")
|
print("返回字段解析错误!")
|
||||||
video_tasks = []
|
video_tasks = []
|
||||||
for index, iteminfo in enumerate(resinfo):
|
for index, iteminfo in enumerate(resinfo):
|
||||||
|
@ -19,18 +19,23 @@ _REDIS_CONF = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# 阈值与批次参数
|
# 阈值与批次参数
|
||||||
QUEUE_PREFIX = "proxy_queue"
|
QUEUE_PREFIX = "proxy_queue"
|
||||||
LOW_WATERMARK = 200
|
LOW_WATERMARK = 200
|
||||||
REFILL_BATCH = 1000
|
REFILL_BATCH = 1000
|
||||||
SLEEP_INTERVAL = 10
|
SLEEP_INTERVAL = 10
|
||||||
|
|
||||||
# 第三方 API 参数
|
# 第三方 API 参数
|
||||||
PROXY_API_URL = "http://api.proxy.roxlabs.io/getProxyIp"
|
PROXY_API_URL = "http://api.proxy.roxlabs.io/getProxyIp"
|
||||||
ACCESS_ID = "2207189"
|
ACCESS_ID = "2207189"
|
||||||
SIGN = "10099426b05c7119e9c4dbd6a7a0aa4e"
|
SIGN = "10099426b05c7119e9c4dbd6a7a0aa4e"
|
||||||
|
|
||||||
db = DB.DBVidcon()
|
db = DB.DBVidcon()
|
||||||
|
|
||||||
|
|
||||||
|
def fetch_proxies2(region_code, n):
|
||||||
|
return [("http://" + region_code.lower() + "-pr.thordata.net:25000") * n]
|
||||||
|
|
||||||
|
|
||||||
def fetch_proxies(region_code, n):
|
def fetch_proxies(region_code, n):
|
||||||
"""
|
"""
|
||||||
从第三方一次性请求 n 条代理,返回格式化列表
|
从第三方一次性请求 n 条代理,返回格式化列表
|
||||||
@ -61,7 +66,7 @@ def fetch_proxies(region_code, n):
|
|||||||
for item in arr:
|
for item in arr:
|
||||||
# user = quote(item["username"], safe="")
|
# user = quote(item["username"], safe="")
|
||||||
# pwd = quote(item["password"], safe="")
|
# pwd = quote(item["password"], safe="")
|
||||||
ip = item["ip"]
|
ip = item["ip"]
|
||||||
port = item["port"]
|
port = item["port"]
|
||||||
# result.append(f"http://{user}:{pwd}@{ip}:{port}")
|
# result.append(f"http://{user}:{pwd}@{ip}:{port}")
|
||||||
result.append(f"http://{ip}:{port}")
|
result.append(f"http://{ip}:{port}")
|
||||||
@ -78,7 +83,7 @@ def refill_queue(r: redis.Redis, region_name: str, region_code: str,
|
|||||||
|
|
||||||
to_fetch = batch - length
|
to_fetch = batch - length
|
||||||
print(f"[{time.strftime('%H:%M:%S')}] {key} 长度 {length} < {low},一次性拉取 {to_fetch} 条…")
|
print(f"[{time.strftime('%H:%M:%S')}] {key} 长度 {length} < {low},一次性拉取 {to_fetch} 条…")
|
||||||
proxies = fetch_proxies(region_code, to_fetch)
|
proxies = fetch_proxies2(region_code, to_fetch)
|
||||||
if proxies:
|
if proxies:
|
||||||
r.rpush(key, *proxies)
|
r.rpush(key, *proxies)
|
||||||
print(f"[{time.strftime('%H:%M:%S')}] 已入队 {len(proxies)} 条 → 新长度 {r.llen(key)}")
|
print(f"[{time.strftime('%H:%M:%S')}] 已入队 {len(proxies)} 条 → 新长度 {r.llen(key)}")
|
||||||
@ -88,7 +93,7 @@ def refill_queue(r: redis.Redis, region_name: str, region_code: str,
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
p = argparse.ArgumentParser(description="多地区代理队列自动补给")
|
p = argparse.ArgumentParser(description="多地区代理队列自动补给")
|
||||||
p.add_argument("--low", "-l", type=int, default=LOW_WATERMARK,
|
p.add_argument("--low", "-l", type=int, default=LOW_WATERMARK,
|
||||||
help="低水位阈值,队列长度低于此值时触发补给")
|
help="低水位阈值,队列长度低于此值时触发补给")
|
||||||
p.add_argument("--batch", "-b", type=int, default=REFILL_BATCH,
|
p.add_argument("--batch", "-b", type=int, default=REFILL_BATCH,
|
||||||
help="单次补给目标条数")
|
help="单次补给目标条数")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user