From c5fe3d9e0bc1633df0994c0d4147081e376f4fef Mon Sep 17 00:00:00 2001 From: zhanghaotian Date: Wed, 26 Aug 2020 17:38:48 +0800 Subject: [PATCH 1/9] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=B0=B7=E6=AD=8C?= =?UTF-8?q?=E7=BF=BB=E8=AF=91=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- trans/translate_func.py | 55 +++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 33 deletions(-) diff --git a/trans/translate_func.py b/trans/translate_func.py index 36cc8e3c..58e35968 100644 --- a/trans/translate_func.py +++ b/trans/translate_func.py @@ -16,11 +16,12 @@ import urllib.request import urllib.parse import json -import requests # pip intasll requests +import requests # pip intasll requests import execjs # 安装指令:pip install PyExecJS import random import hashlib +from googletrans import Translator class Py4Js(): @@ -66,59 +67,47 @@ def __init__(self): return a } """) + def getTk(self, text): return self.ctx.call("TL", text) + # 有道翻译方法,不支持一次翻译一大段文字 def youdao_translate(content): '''实现有道翻译的接口''' url = 'http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&sessionFrom=https://www.baidu.com/link' data = { - 'from':'AUTO', - 'to':'AUTO', - 'smartresult':'dict', - 'client':'fanyideskweb', - 'salt':'1500092479607', - 'sign':'d9f9a3aa0a7b34241b3fe30505e5d436', - 'doctype':'json', - 'version':'2.1', - 'keyfrom':'fanyi.web', - 'action':'FY_BY_CL1CKBUTTON', - 'typoResult':'true'} - data['i'] = content.replace('\n','') + 'from': 'AUTO', + 'to': 'AUTO', + 'smartresult': 'dict', + 'client': 'fanyideskweb', + 'salt': '1500092479607', + 'sign': 'd9f9a3aa0a7b34241b3fe30505e5d436', + 'doctype': 'json', + 'version': '2.1', + 'keyfrom': 'fanyi.web', + 'action': 'FY_BY_CL1CKBUTTON', + 'typoResult': 'true'} + data['i'] = content.replace('\n', '') data = urllib.parse.urlencode(data).encode('utf-8') - wy = urllib.request.urlopen(url,data) + wy = urllib.request.urlopen(url, data) html = wy.read().decode('utf-8') ta = json.loads(html) res = ta['translateResult'][0][0]['tgt'] return res + # 谷歌翻译方法 def google_translate(content): '''实现谷歌的翻译''' - - content = content.replace('\n','') - print(content) - js = Py4Js() - tk = js.getTk(content) - if len(content) > 4891: - return '输入请不要超过4891个字符!' - param = {'tk': tk, 'q': content} - result = requests.get("""http://translate.google.cn/translate_a/single?client=t&sl=en - &tl=zh-CN&hl=zh-CN&dt=at&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss - &dt=t&ie=UTF-8&oe=UTF-8&clearbtn=1&otf=1&pc=1&srcrom=0&ssel=0&tsel=0&kc=2""", params=param) - #返回的结果为Json,解析为一个嵌套列表 - trans = result.json()[0] - res = '' - for i in range(len(trans)): - line = trans[i][0] - if line != None: - res += trans[i][0] + content = content.replace('\n', '') + trans = Translator(service_urls=["translate.google.cn"]) + res = trans.translate(content, dest='zh-cn').text return res -def is_Chinese(content): #判断输入的内容是否是中文 +def is_Chinese(content): # 判断输入的内容是否是中文 for ch in content: if '\u4e00' <= ch <= '\u9fff': return True From a5ed3a8e0c48433902a7d6ef387f352389faae08 Mon Sep 17 00:00:00 2001 From: zhanghaotian Date: Thu, 27 Aug 2020 18:06:00 +0800 Subject: [PATCH 2/9] reinit the project --- templates/index.html | 6 +++--- ...g Clustered Anomalies Using SCiForest.docx | Bin 36670 -> 0 bytes ...tion Using Nearest Neighbour Ensemble.docx | Bin 36695 -> 0 bytes ...ARNING FOR ANOMALY DETECTION A SURVEY.docx | Bin 2366745 -> 0 bytes ...d_2019_DistributionForestAnAnomalyDet.docx | Bin 585800 -> 0 bytes .../translated_2019_SCiForestUsing.docx | Bin 36601 -> 0 bytes trans/output_file/translated_test1.docx | Bin 36670 -> 0 bytes .../\345\233\276\347\211\2071.png" | Bin 67 -> 0 bytes .../\345\233\276\347\211\2072.png" | Bin 86 -> 0 bytes 9 files changed, 3 insertions(+), 3 deletions(-) delete mode 100644 trans/output_file/translated_2010_On Detecting Clustered Anomalies Using SCiForest.docx delete mode 100644 trans/output_file/translated_2014_Efficient Anomaly Detection by Isolation Using Nearest Neighbour Ensemble.docx delete mode 100644 trans/output_file/translated_2019_DEEP LEARNING FOR ANOMALY DETECTION A SURVEY.docx delete mode 100644 trans/output_file/translated_2019_DistributionForestAnAnomalyDet.docx delete mode 100644 trans/output_file/translated_2019_SCiForestUsing.docx delete mode 100644 trans/output_file/translated_test1.docx delete mode 100644 "trans/output_file/\345\233\276\347\211\2071.png" delete mode 100644 "trans/output_file/\345\233\276\347\211\2072.png" diff --git a/templates/index.html b/templates/index.html index 5216fe40..3cb08ca7 100644 --- a/templates/index.html +++ b/templates/index.html @@ -4,14 +4,14 @@ - EasyTrans + QuickTrans
- +