Python写的翻译工具

功能介绍:程序自动读取剪贴板字符串,如果字符串为非中文,均翻译为中文,如果字符串为中文,则翻译为英文,如果字符串为网址,则不进行任意操作,tkk代码部分取自github,脚本支持http/https代理,非代理请求google.cn,代理则请求google.com,使用代理模式时,脚本会创建proxy.ini,可以修改该文件来修改代理地址,格式:127.0.0.1:8080

下面是完整代码

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import requests
import os
import random
import win32clipboard as wc
import time
import tkinter as tk
import ctypesproxies = {}
root=tk.Tk()
root.withdraw()
baseurl = ["https://translate.google.com/translate_a/single?client=gtx&dt=t&dj=1&ie=UTF-8&sl=auto&tl=","http://translate.google.cn/translate_a/single?client=gtx&dt=t&dj=1&ie=UTF-8&sl=auto&tl="]
s = ""
pd = 0 #proxies id
pl = [] #proxies listdef select_proxy():global proxieswhile True:id = input("是否启用代理(默认不启用)?Y/N")if id == "Y" or id == "y":check()os.system("title 【当前使用代理翻译】")returnelif id == "N" or id == "n":proxies = {}os.system("title 【当前使用直连翻译】")returnelse:proxies = {}os.system("title 【当前使用直连翻译】")returnua = ["Mozilla/5.0 (iPhone 84; CPU iPhone OS 10_3_3 like Mac OS X) AppleWebKit/603.3.8 (KHTML, like Gecko) Version/10.0 MQQBrowser/7.8.0 Mobile/14G60 Safari/8536.25 MttCustomUA/2 QBWebViewType/1 WKType/1","Mozilla/5.0 (Linux; Android 7.0; STF-AL10 Build/HUAWEISTF-AL10; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/53.0.2785.49 Mobile MQQBrowser/6.2 TBS/043508 Safari/537.36 V1_AND_SQ_7.2.0_730_YYB_D QQ/7.2.0.3270 NetType/4G WebP/0.3.0 Pixel/1080","Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_3 like Mac OS X) AppleWebKit/603.3.8 (KHTML, like Gecko) Mobile/14G60 MicroMessenger/6.5.18 NetType/WIFI Language/en",


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部