Files
kami_itunes_third_api/src/service/proxy.py
danial 371fe49d1a feat(service): 添加代理服务并更新相关功能
- 新增 ProxyService 类,用于管理代理服务器
- 在 iTunes 服务中集成代理服务
- 更新 .gitignore 文件,添加新忽略项
- 在配置文件中添加代理服务器地址
- 更新相关模块以支持代理服务
2024-10-31 00:36:33 +08:00

37 lines
1014 B
Python

import copy
from time import time
from src.initialization import setting
import random
# 账户列表
account_list = {}
class ProxyService:
def get_wrap_proxy(self, account_name: str):
proxy = self.get_proxy(account_name)
return {
"http": proxy,
"https": proxy,
}
def get_proxy(self, account_name: str):
self.set_expire_strategy()
if account_name in account_list:
return account_list[account_name].address
return self.set_proxy(account_name)
def set_proxy(self, account_name: str):
proxy = random.choice(setting.proxies.address)
account_list[account_name] = {
"address": proxy,
"timeout": time.time() + 60 * 60 * 24,
}
return proxy
# 设置触发账号过期策略
def set_expire_strategy(self):
for key, value in copy.deepcopy(account_list).items():
if value.get("timeout") > time.time():
account_list.pop(key)