感谢!
mark.
奇怪了,始皇的站能用但是没扫到
response.status_code == 200
并不能完全保证服务可用,因为有一部分接口返回200,但是内容是翻译失败
建议把条件写成
response.status_code == 200 and ('data' in response.json() and len(str(response.json().get("data"))) > 0)
mark了
欧克,加上了
咨询个事情: 如果写了多个API URL, 那么执行的时候是啥情况?
是一次查询会向所有的URL发送请求, 选取最快的结果.
还是轮流使用每个URL, 做到负载均衡?
import tkinter as tk
from tkinter import filedialog, messagebox, ttk
import requests
import time
import os
import threading
class DeepLCheckerApp:
def __init__(self, root):
self.root = root
self.root.title('DeepL URL 检查器')
# 设置 GUI 布局
self.frame = ttk.Frame(self.root, padding="10")
self.frame.grid(row=0, column=0, sticky=(tk.W, tk.E, tk.N, tk.S))
# 按钮选择输入文件
self.choose_button = ttk.Button(self.frame, text="选择输入txt文件(一行一个)", command=self.load_file)
self.choose_button.grid(row=0, column=0, pady=10)
# 显示已选文件路径的标签
self.file_label = ttk.Label(self.frame, text="未选择文件")
self.file_label.grid(row=1, column=0, pady=10)
# 进度条
self.progress = ttk.Progressbar(self.frame, length=200, mode='determinate')
self.progress.grid(row=2, column=0, pady=20)
# 输出文本框
self.results_text = tk.Text(self.frame, height=10, width=50)
self.results_text.grid(row=3, column=0, pady=10)
# 开始和停止检查的按钮
self.start_button = ttk.Button(self.frame, text="开始检查", command=self.start_checking, state=tk.DISABLED)
self.start_button.grid(row=4, column=0, padx=5, pady=5)
self.stop_button = ttk.Button(self.frame, text="终止检查", command=self.stop_checking, state=tk.DISABLED)
self.stop_button.grid(row=5, column=0, padx=5, pady=5)
self.check_thread = None
self.running = False
def load_file(self):
file_path = filedialog.askopenfilename()
if file_path:
self.file_label.config(text=file_path)
self.start_button.config(state=tk.NORMAL)
def start_checking(self):
self.start_button.config(state=tk.DISABLED)
self.stop_button.config(state=tk.NORMAL)
self.running = True
self.check_thread = threading.Thread(target=self.check_urls, args=(self.file_label['text'],))
self.check_thread.start()
def stop_checking(self):
self.running = False
self.stop_button.config(state=tk.DISABLED)
def check_urls(self, file_path):
with open(file_path, "r") as file:
deepl_urls = [line.strip() for line in file if line.strip()]
test_data = {
"text": "Hello, world!",
"source_lang": "EN",
"target_lang": "ZH"
}
total_urls = len(deepl_urls)
self.progress['maximum'] = total_urls
output_path = os.path.join(os.path.dirname(file_path), 'useful.txt')
with open(output_path, 'w') as output_file:
for index, url in enumerate(deepl_urls):
if not self.running:
break
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 response.json().get("data"):
output_file.write(f"{url} ({latency:.2f}s)\n")
self.results_text.insert(tk.END, f"✅ 可用: {url} ({latency:.2f}s)\n")
else:
self.results_text.insert(tk.END, f"❌ 不可用: {url}\n")
except requests.exceptions.RequestException as e:
self.results_text.insert(tk.END, f"❌ 错误: {url} {e}\n")
self.progress['value'] = index + 1
self.root.update()
messagebox.showinfo("完成", "所有URL检查完成。结果已保存至 useful.txt")
self.start_button.config(state=tk.NORMAL)
self.stop_button.config(state=tk.DISABLED)
# 设置主应用窗口
root = tk.Tk()
app = DeepLCheckerApp(root)
root.mainloop()
改进一下,直接输入url的txt,一行一个地址就行,能用的会自动保存到useful.txt。
支持一下
支持一下
Available DeepLX Endpoints with Latencies:
------------------------------------------------------------
🚀 (0.40s) http://49.233.41.73:1188/translate
🚀 (0.40s) http://117.50.183.46:1188/translate
🚀 (0.41s) http://82.157.137.187:1188/translate
🚀 (0.41s) http://49.232.164.78:1188/translate
🚀 (0.44s) http://hc-beijing.rhythmlian.cn:8085/translate
🚀 (0.46s) http://101.43.76.234:1188/translate
🚀 (0.46s) http://49.235.73.101:1188/translate
🚀 (0.49s) http://119.91.152.74:1188/translate
🚀 (0.50s) http://175.178.237.179:1188/translate
🚀 (0.50s) http://1.12.243.147:1188/translate
🚀 (0.53s) http://deeplx.hc-beijing.rhythmlian.cn/translate
🚀 (0.54s) http://106.14.17.223:1188/translate
🚀 (0.78s) http://8.142.134.155:1188/translate
🚀 (0.89s) http://82.156.36.11:1188/translate
🚀 (1.38s) http://195.154.184.125:1188/translate
🚀 (1.41s) http://162.55.35.20:1188/translate
🚀 (1.43s) http://157.90.115.116:1188/translate
🚀 (1.44s) http://116.203.83.80:1188/translate
🚀 (1.48s) http://43.153.38.254:1188/translate
🚀 (1.49s) http://104.234.60.178:1188/translate
🚀 (1.50s) http://209.141.49.210:1188/translate
🚀 (1.51s) http://38.148.254.10:1188/translate
🚀 (1.51s) http://64.112.42.240:1188/translate
🚀 (1.53s) http://129.153.73.237:1188/translate
🚀 (1.53s) http://148.135.107.108:1188/translate
🚀 (1.53s) http://46.8.19.173:1188/translate
🚀 (1.55s) http://45.145.72.29:1188/translate
🚀 (1.55s) http://107.175.28.239:1188/translate
🚀 (1.80s) http://168.138.34.126:1188/translate
🚀 (1.82s) http://168.138.214.221:1188/translate
🚀 (1.84s) http://132.226.14.46:1188/translate
🚀 (1.86s) http://211.227.72.101:1188/translate
🚀 (1.87s) http://132.145.80.159:1188/translate
🚀 (1.89s) http://203.25.119.208:1188/translate
🚀 (1.89s) http://37.123.196.26:1188/translate
🚀 (1.89s) http://103.152.35.2:1188/translate
🚀 (1.90s) http://123.60.157.70:8085/translate
🚀 (1.95s) http://43.138.68.36:8085/translate
🚀 (1.96s) http://207.148.127.142:1188/translate
🚀 (1.98s) http://157.245.192.219:1188/translate
🚀 (1.99s) http://18.142.80.110:1188/translate
🚀 (2.01s) http://134.122.133.65:1188/translate
🚀 (2.02s) http://146.56.97.135:1188/translate
🚀 (2.04s) http://152.67.211.94:1188/translate
🚀 (2.05s) http://134.122.133.56:1188/translate
🚀 (2.06s) http://134.122.133.76:1188/translate
🚀 (2.37s) https://api.deeplx.org/translate
🚀 (2.48s) https://deeplx.keyrotate.com/translate
🚀 (2.48s) https://deeplx.papercar.top/translate
🚀 (2.51s) https://dlx.bitjss.com/translate
🚀 (2.55s) https://deepl.coloo.org/translate
🚀 (2.66s) https://deepl.zhaosaipo.com/translate
🚀 (2.67s) https://free-deepl.speedcow.top/translate
🚀 (3.04s) https://deepl.aimoyu.tech/translate
🚀 (3.39s) https://deepx.dumpit.top/translate
🚀 (3.61s) https://deep.jftkj.cyou/translate
🚀 (3.65s) https://dx-api.nosec.link/translate
🚀 (4.99s) http://194.87.252.161:1188/translate
------------------------------------------------------------
DeepLX👌:(58) http://49.233.41.73:1188/translate, http://117.50.183.46:1188/translate, http://82.157.137.187:1188/translate, http://49.232.164.78:1188/translate, http://hc-beijing.rhythmlian.cn:8085/translate, http://101.43.76.234:1188/translate, http://49.235.73.101:1188/translate, http://119.91.152.74:1188/translate, http://175.178.237.179:1188/translate, http://1.12.243.147:1188/translate, http://deeplx.hc-beijing.rhythmlian.cn/translate, http://106.14.17.223:1188/translate, http://8.142.134.155:1188/translate, http://82.156.36.11:1188/translate, http://195.154.184.125:1188/translate, http://162.55.35.20:1188/translate, http://157.90.115.116:1188/translate, http://116.203.83.80:1188/translate, http://43.153.38.254:1188/translate, http://104.234.60.178:1188/translate, http://209.141.49.210:1188/translate, http://38.148.254.10:1188/translate, http://64.112.42.240:1188/translate, http://129.153.73.237:1188/translate, http://148.135.107.108:1188/translate, http://46.8.19.173:1188/translate, http://45.145.72.29:1188/translate, http://107.175.28.239:1188/translate, http://168.138.34.126:1188/translate, http://168.138.214.221:1188/translate, http://132.226.14.46:1188/translate, http://211.227.72.101:1188/translate, http://132.145.80.159:1188/translate, http://203.25.119.208:1188/translate, http://37.123.196.26:1188/translate, http://103.152.35.2:1188/translate, http://123.60.157.70:8085/translate, http://43.138.68.36:8085/translate, http://207.148.127.142:1188/translate, http://157.245.192.219:1188/translate, http://18.142.80.110:1188/translate, http://134.122.133.65:1188/translate, http://146.56.97.135:1188/translate, http://152.67.211.94:1188/translate, http://134.122.133.56:1188/translate, http://134.122.133.76:1188/translate, https://api.deeplx.org/translate, https://deeplx.keyrotate.com/translate, https://deeplx.papercar.top/translate, https://dlx.bitjss.com/translate, https://deepl.coloo.org/translate, https://deepl.zhaosaipo.com/translate, https://free-deepl.speedcow.top/translate, https://deepl.aimoyu.tech/translate, https://deepx.dumpit.top/translate, https://deep.jftkj.cyou/translate, https://dx-api.nosec.link/translate, http://194.87.252.161:1188/translate
建议取url改为从文件中取,比如
with open('url.txt', 'r') as file:
deepl_urls = [line.strip() for line in file]
简单修改一下,增加多线程功能
import requests
import time
import threading
from tqdm import tqdm
import argparse
import os
# 命令行参数解析
parser = argparse.ArgumentParser(description='检查 DeepLX 接口。')
parser.add_argument('-t', '--threads', type=int, default=5, help='要使用的线程数。')
args = parser.parse_args()
# DeepLX 接口列表
with open('url.txt', 'r') as file:
deepl_urls = [line.strip() for line in file]
# 测试请求参数
test_data = {
"text": "Hello, world!",
"source_lang": "EN",
"target_lang": "ZH"
}
# 用来收集可用接口及其响应时间
available_endpoints = []
lock = threading.Lock()
# 检测每个接口的可用性和延迟
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):
with lock:
available_endpoints.append((url, latency))
except requests.exceptions.RequestException:
pass # 忽略错误,只关注可用接口
# 创建线程
threads = []
for url in tqdm(deepl_urls, desc="检查接口中"):
t = threading.Thread(target=check_endpoint, args=(url,))
t.start()
threads.append(t)
# 限制最大线程数
while threading.active_count() > args.threads:
time.sleep(0.1)
# 等待所有线程完成
for t in threads:
t.join()
# 根据延迟时间排序接口
available_endpoints.sort(key=lambda x: x[1])
# 写入所有可用的接口到 success.txt,按延迟时间排序
if available_endpoints:
with open('success.txt', 'w') as f:
for endpoint in available_endpoints:
f.write(f"{endpoint[0]}\n")
else:
print("未找到可用的接口。\n")
DeepLX:(10) https://api.deeplx.org/translate, https://dlx.bitjss.com/translate, https://deeplx.papercar.top/translate, https://deepl.aimoyu.tech/translate, https://deeplx.keyrotate.com/translate, https://deepl.coloo.org/translate, https://deepl.zhaosaipo.com/translate, https://dx-api.nosec.link/translate, https://deepx.dumpit.top/translate, https://free-deepl.speedcow.top/translate