feat: 全面SSH中转代理 + mimo-v2.5-pro支持
- Yahoo Finance: 跳过本地限流,直接走SSH中转 - StockTwits: 直连403时自动fallback到SSH中转 - Reddit: 网络不可达时自动fallback到SSH中转 - Polymarket: 网络不可达时自动fallback到SSH中转 - FRED: 配置API Key (825283926dd016ea66e96cc919e047da) - .env: 新增FRED_API_KEY和OPENAI_COMPATIBLE_API_KEY - test_xiaomi.py: 小米mimo-v2.5-pro测试脚本
This commit is contained in:
1 parent
51d057e2c9
commit
f8a47cb473
6 files changed
+93
-49
No files matched your search
@@ -13,8 +13,12 @@ import json
|
||||
import logging
|
||||
from datetime import datetime, timezone
|
||||
|
||||
import subprocess
|
||||
|
||||
import requests
|
||||
|
||||
from .stockstats_utils import _get_ssh_config
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
GAMMA_BASE = "https://gamma-api.polymarket.com"
|
||||
@@ -27,11 +31,28 @@ DEFAULT_LIMIT = 6
|
||||
|
||||
|
||||
def _request(path: str, params: dict) -> dict:
|
||||
response = requests.get(
|
||||
f"{GAMMA_BASE}/{path}", params=params, timeout=REQUEST_TIMEOUT
|
||||
)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
url = f"{GAMMA_BASE}/{path}"
|
||||
try:
|
||||
response = requests.get(url, params=params, timeout=REQUEST_TIMEOUT)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
except requests.RequestException:
|
||||
# Fallback: fetch through SSH proxy
|
||||
logger.info("Polymarket direct failed, trying SSH proxy for %s...", path)
|
||||
query = "&".join(f"{k}={v}" for k, v in params.items())
|
||||
full_url = f"{url}?{query}"
|
||||
host, port, password = _get_ssh_config()
|
||||
cmd = [
|
||||
"sshpass", "-p", password,
|
||||
"ssh", "-o", "StrictHostKeyChecking=no",
|
||||
"-o", "ConnectTimeout=15",
|
||||
"-p", str(port), f"root@{host}",
|
||||
f'curl -s "{full_url}"'
|
||||
]
|
||||
result = subprocess.run(cmd, capture_output=True, text=True, timeout=REQUEST_TIMEOUT)
|
||||
if result.returncode != 0:
|
||||
raise requests.RequestException(f"SSH proxy failed: {result.stderr}")
|
||||
return json.loads(result.stdout)
|
||||
|
||||
|
||||
def _parse_json_list(value) -> list:
|
||||
|
||||
Reference in new issue
Block a user