commit
This commit is contained in:
98
backend/damai_proxy_config.py
Normal file
98
backend/damai_proxy_config.py
Normal file
@@ -0,0 +1,98 @@
|
||||
"""
|
||||
大麦固定代理IP配置
|
||||
用于在无头浏览器中使用固定代理IP
|
||||
"""
|
||||
|
||||
# 大麦固定代理IP池
|
||||
DAMAI_PROXY_POOL = [
|
||||
{
|
||||
"name": "大麦代理1",
|
||||
"server": "http://36.137.177.131:50001",
|
||||
"username": "qqwvy0",
|
||||
"password": "mun3r7xz",
|
||||
"enabled": True
|
||||
},
|
||||
{
|
||||
"name": "大麦代理2",
|
||||
"server": "http://111.132.40.72:50002",
|
||||
"username": "ih3z07",
|
||||
"password": "078bt7o5",
|
||||
"enabled": True
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def get_proxy_config(index: int = 0) -> dict:
|
||||
"""
|
||||
获取指定索引的代理配置
|
||||
|
||||
Args:
|
||||
index: 代理索引(0或1)
|
||||
|
||||
Returns:
|
||||
代理配置字典,包含server、username、password
|
||||
"""
|
||||
if index < 0 or index >= len(DAMAI_PROXY_POOL):
|
||||
raise ValueError(f"代理索引无效: {index},有效范围: 0-{len(DAMAI_PROXY_POOL)-1}")
|
||||
|
||||
proxy = DAMAI_PROXY_POOL[index]
|
||||
if not proxy.get("enabled", True):
|
||||
raise ValueError(f"代理已禁用: {proxy['name']}")
|
||||
|
||||
return {
|
||||
"server": proxy["server"],
|
||||
"username": proxy["username"],
|
||||
"password": proxy["password"]
|
||||
}
|
||||
|
||||
|
||||
def get_all_enabled_proxies() -> list:
|
||||
"""
|
||||
获取所有已启用的代理配置
|
||||
|
||||
Returns:
|
||||
代理配置列表
|
||||
"""
|
||||
return [
|
||||
{
|
||||
"server": p["server"],
|
||||
"username": p["username"],
|
||||
"password": p["password"],
|
||||
"name": p["name"]
|
||||
}
|
||||
for p in DAMAI_PROXY_POOL
|
||||
if p.get("enabled", True)
|
||||
]
|
||||
|
||||
|
||||
def get_random_proxy() -> dict:
|
||||
"""
|
||||
随机获取一个可用的代理配置
|
||||
|
||||
Returns:
|
||||
代理配置字典
|
||||
"""
|
||||
import random
|
||||
enabled_proxies = [p for p in DAMAI_PROXY_POOL if p.get("enabled", True)]
|
||||
|
||||
if not enabled_proxies:
|
||||
raise ValueError("没有可用的代理")
|
||||
|
||||
proxy = random.choice(enabled_proxies)
|
||||
return {
|
||||
"server": proxy["server"],
|
||||
"username": proxy["username"],
|
||||
"password": proxy["password"],
|
||||
"name": proxy["name"]
|
||||
}
|
||||
|
||||
|
||||
# 快捷访问
|
||||
def get_proxy_1():
|
||||
"""获取代理1配置"""
|
||||
return get_proxy_config(0)
|
||||
|
||||
|
||||
def get_proxy_2():
|
||||
"""获取代理2配置"""
|
||||
return get_proxy_config(1)
|
||||
Reference in New Issue
Block a user