From bbd010b4978319a607d70a08ae204ebc45a40a41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=AC=E9=97=B4=E7=99=BD=E7=8C=AB?= <139044047+honmashironeko@users.noreply.github.com> Date: Tue, 14 Jan 2025 11:30:01 +0800 Subject: [PATCH] Update --- config/getip.py | 32 +++++++++++++++++++++++--------- modules/modules.py | 8 +++----- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/config/getip.py b/config/getip.py index 334a561..99bf866 100644 --- a/config/getip.py +++ b/config/getip.py @@ -1,17 +1,31 @@ from modules.modules import get_message, load_config import requests +first_run_flag = True + def newip(): + global first_run_flag config = load_config() language = config.get('language', 'cn') - print(get_message('getting_new_proxy', language)) - url = config.get('getip_url', '') - if not url: - raise ValueError(get_message('proxy_file_not_found', language, 'getip_url')) - response = requests.get(url) - response.raise_for_status() - newip = "socks5://" + response.text.split("\r\n")[0] - print(get_message('new_proxy_is', language, newip)) - return newip + try: + if first_run_flag: + appKey = "" + anquanma = "" + whitelist_url = f"https://sch.shanchendaili.com/api.html?action=addWhiteList&appKey={appKey}&anquanma={anquanma}" + requests.get(whitelist_url).raise_for_status() + first_run_flag = False + + url = config.get('getip_url', '') + if not url: + raise ValueError('getip_url') + + response = requests.get(url) + response.raise_for_status() + return "socks5://" + response.text.split("\r\n")[0] + + except Exception as e: + error_msg = 'whitelist_error' if first_run_flag else 'proxy_file_not_found' + print(get_message(error_msg, language, str(e))) + raise diff --git a/modules/modules.py b/modules/modules.py index 20046fd..901d7cb 100644 --- a/modules/modules.py +++ b/modules/modules.py @@ -73,8 +73,7 @@ MESSAGES = { 'consecutive_failures': '检测到连续代理失败: {}', 'invalid_proxy': '当前代理无效: {}', 'proxy_switched': '已从代理 {} 切换到 {}', - 'consecutive_failures': '检测到连续代理失败: {}', - 'invalid_proxy': '当前代理无效: {}' + 'whitelist_error': '添加白名单失败: {}' }, 'en': { 'getting_new_proxy': 'Getting new proxy IP', @@ -146,8 +145,7 @@ MESSAGES = { 'consecutive_failures': 'Consecutive proxy failures detected for {}', 'invalid_proxy': 'Current proxy is invalid: {}', 'proxy_switched': 'Switched from proxy {} to {}', - 'consecutive_failures': 'Consecutive proxy failures detected for {}', - 'invalid_proxy': 'Current proxy is invalid: {}' + 'whitelist_error': 'Failed to add whitelist: {}' } } @@ -344,7 +342,7 @@ async def check_for_updates(language='cn'): match = re.search(r'

(ProxyCat-V\d+\.\d+\.\d+)

', content) if match: latest_version = match.group(1) - CURRENT_VERSION = "ProxyCat-V1.9.3" + CURRENT_VERSION = "ProxyCat-V1.9.4" if version.parse(latest_version.split('-V')[1]) > version.parse(CURRENT_VERSION.split('-V')[1]): print(f"{Fore.YELLOW}{get_message('new_version_found', language)} 当前版本: {CURRENT_VERSION}, 最新版本: {latest_version}") print(f"{Fore.YELLOW}{get_message('visit_quark', language)}")