Files
ai_wht_wechat/backend/damai_proxy_config.py
2026-01-06 19:36:42 +08:00

99 lines
2.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
大麦固定代理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)