一元网络论坛

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 75|回复: 0

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

[复制链接]

1万

主题

1万

帖子

5万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
55819
发表于 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[1])
# 打印可用接口及延迟
print("\nAvailable DeepLX Endpoints with Latencies:")
print("-" * 60)
for endpoint, delay in available_endpoints:
    print(f"
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|一元网络论坛

GMT+8, 2024-9-19 12:20 , Processed in 0.114208 second(s), 19 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表