135 lines
5.3 KiB
Python
135 lines
5.3 KiB
Python
import requests
|
|
import json
|
|
import os
|
|
from datetime import datetime
|
|
|
|
# --- 配置保持不变 ---
|
|
BASE_URL = "http://106.75.72.40:7500/api/proxy/tcp"
|
|
PRIMARY_AUTH = "Basic YWRtaW46bGljYWhr"
|
|
X_AUTH = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7ImlkIjoxLCJsb2NhbGUiOiJ6aC1jbiIsInZpZXdNb2RlIjoibGlzdCIsInNpbmdsZUNsaWNrIjpmYWxzZSwicGVybSI6eyJhZG1pbiI6dHJ1ZSwiZXhlY3V0ZSI6dHJ1ZSwiY3JlYXRlIjp0cnVlLCJyZW5hbWUiOnRydWUsIm1vZGlmeSI6dHJ1ZSwiZGVsZXRlIjp0cnVlLCJzaGFyZSI6dHJ1ZSwiZG93bmxvYWQiOnRydWV9LCJjb21tYW5kcyI6W10sImxvY2tQYXNzd29yZCI6ZmFsc2UsImhpZGVEb3RmaWxlcyI6ZmFsc2V9LCJleHAiOjE3Njc2Njg3NzgsImlhdCI6MTc2NzY2MTU3OCwiaXNzIjoiRmlsZSBCcm93c2VyIn0.z9zycFSf3XpUDRhGjziUJ-PUeHIsRba23AI6itqXM-w"
|
|
|
|
headers = {
|
|
"Authorization": PRIMARY_AUTH,
|
|
"x-auth": X_AUTH,
|
|
"User-Agent": "Mozilla/5.0"
|
|
}
|
|
|
|
|
|
def get_today_str():
|
|
return datetime.now().strftime("%Y_%m_%d")
|
|
|
|
|
|
def find_closest_item(items, is_date_level=True):
|
|
if not items or not isinstance(items, list): return None
|
|
today = datetime.now()
|
|
scored_items = []
|
|
for item in items:
|
|
if not isinstance(item, dict): continue
|
|
path = item.get('path', '')
|
|
if not path: continue
|
|
try:
|
|
if is_date_level:
|
|
date_str = path.split('/')[-1]
|
|
current_date = datetime.strptime(date_str, "%Y_%m_%d")
|
|
else:
|
|
mod_str = item.get('modified', '')
|
|
if mod_str:
|
|
current_date = datetime.fromisoformat(mod_str.replace('Z', '+00:00'))
|
|
else:
|
|
continue
|
|
diff = abs((today - current_date.replace(tzinfo=None)).total_seconds())
|
|
scored_items.append((diff, item))
|
|
except:
|
|
continue
|
|
|
|
if not scored_items: return None
|
|
scored_items.sort(key=lambda x: x[0])
|
|
return scored_items[0][1]
|
|
|
|
|
|
def debug_process_106():
|
|
today_str = get_today_str()
|
|
print(f"=== 开始 106 网站深度调试 (目标日期: {today_str}) ===")
|
|
|
|
try:
|
|
resp = requests.get(BASE_URL, headers=headers, timeout=15)
|
|
if resp.status_code != 200:
|
|
print(f"❌ 错误: 主接口访问失败, 状态码: {resp.status_code}")
|
|
return
|
|
|
|
proxies = resp.json().get('proxies', [])
|
|
data_proxies = [p for p in proxies if p.get('name', '').endswith('_data')]
|
|
|
|
for item in data_proxies:
|
|
name = item.get('name', 'Unknown')
|
|
# 每一个站点的处理都包裹在独立的 try 里,防止相互干扰
|
|
try:
|
|
status = str(item.get('status', '')).lower().strip()
|
|
conf = item.get('conf') or {}
|
|
port = conf.get('remote_port')
|
|
|
|
print(f"--- [检查站点: {name}] ---")
|
|
|
|
if status != 'online':
|
|
print(f" ⚠ 判定错误: 站点离线 ({status})")
|
|
continue
|
|
|
|
if not port:
|
|
print(f" ❌ 判定错误: 缺少端口配置")
|
|
continue
|
|
|
|
# Data 目录请求
|
|
res2 = requests.get(f"http://106.75.72.40:{port}/api/resources/Data/", headers=headers, timeout=10)
|
|
if res2.status_code != 200:
|
|
print(f" ❌ 判定错误: Data目录 HTTP {res2.status_code}")
|
|
continue
|
|
|
|
it2 = res2.json().get('items', [])
|
|
closest_date = find_closest_item(it2, True)
|
|
if not closest_date:
|
|
print(f" ❌ 判定错误: Data目录为空")
|
|
continue
|
|
|
|
path_date = closest_date.get('path', '')
|
|
date_val = path_date.split('/')[-1]
|
|
|
|
if date_val != today_str:
|
|
print(f" ⚠ 判定错误: 日期不符 (最新: {date_val})")
|
|
continue
|
|
|
|
# 文件列表请求
|
|
res3 = requests.get(f"http://106.75.72.40:{port}/api/resources{path_date}/", headers=headers,
|
|
timeout=10)
|
|
it3 = res3.json().get('items', [])
|
|
closest_file = find_closest_item(it3, False)
|
|
if not closest_file:
|
|
print(f" ❌ 判定错误: 日期文件夹内无文件")
|
|
continue
|
|
|
|
# 文件内容请求 - 关键防御点
|
|
path_csv = closest_file.get('path', '')
|
|
res4 = requests.get(f"http://106.75.72.40:{port}/api/resources{path_csv}", headers=headers, timeout=10)
|
|
|
|
try:
|
|
file_data = res4.json()
|
|
if file_data is None:
|
|
print(f" ❌ 判定错误: 接口返回了 Null (NoneType)")
|
|
continue
|
|
|
|
content = file_data.get('content', '')
|
|
if not content:
|
|
print(f" ❌ 判定错误: content 字段为空")
|
|
else:
|
|
print(f" ✅ 检查通过: 数据最新,长度 {len(content)}")
|
|
except Exception as json_e:
|
|
print(f" ❌ 判定错误: 解析 JSON 失败 (非标准格式)")
|
|
|
|
except Exception as site_e:
|
|
print(f" ❌ 判定错误: 站点逻辑崩溃: {site_e}")
|
|
|
|
except Exception as global_e:
|
|
print(f"❌ 全局严重错误: {global_e}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
debug_process_106() |