admin 发表于 2024-8-16 08:43:17

deeplx多线程检测脚本,支持进度显示。

## DeepLX 代理地址一键测速测活脚本
**灵感来源:** (https://linux.do/t/topic/60674)
**DeepLX 服务介绍:** [沉浸式翻译 DeepLX 教程](https://linux.do/t/topic/40146)
```python
import requests
import time
from concurrent.futures import ThreadPoolExecutor, as_completed
from tqdm import tqdm
# DeepLX 接口列表
deepl_urls = [
    "http://82.157.137.187:1188/translate",
    "https://api.deeplx.org/translate",
    "https://deeplx.vercel.app/translate",
    # ... 其他接口地址 ...
]
# 测试请求参数
test_data = {
    "text": "Hello, world!",
    "source_lang": "EN",
    "target_lang": "ZH"
}
# 可用接口及响应时间
available_endpoints = []
# 请求函数
def check_endpoint(url):
    try:
      start_time = time.time()
      response = requests.post(url, json=test_data, timeout=5)
      latency = time.time() - start_time
      if response.status_code == 200 and 'data' in response.json() and len(str(response.json().get("data"))) > 0:
            return (url, latency)
    except requests.exceptions.RequestException:
      return None
# 多线程检查接口可用性和延迟
with ThreadPoolExecutor(max_workers=5) as executor:
    futures = {executor.submit(check_endpoint, url): url for url in deepl_urls}
    for future in tqdm(as_completed(futures), total=len(futures), desc="Checking endpoints"):
      result = future.result()
      if result:
            available_endpoints.append(result)
# 延迟排序接口
available_endpoints.sort(key=lambda x: x)
# 打印可用接口及延迟
print("\nAvailable DeepLX Endpoints with Latencies:")
print("-" * 60)
for endpoint, delay in available_endpoints:
    print(f"
页: [1]
查看完整版本: deeplx多线程检测脚本,支持进度显示。