(1)小强版
import http.client
import hashlib
import urllib
import random
import json
def etoc(text):
appid = '' # 填写你的appid
secretKey = '' # 填写你的密钥
myurl = '/api/trans/vip/translate'
fromLang = 'auto' # 原文语种
toLang = 'zh' # 译文语种
salt = random.randint(32768, 65536)
q = text
sign = appid + q + str(salt) + secretKey
sign = hashlib.md5(sign.encode()).hexdigest()
myurl = myurl + '?appid=' + appid + '&q=' + urllib.parse.quote(
q) + '&from=' + fromLang + '&to=' + toLang + '&salt=' + str(
salt) + '&sign=' + sign
try:
httpClient = http.client.HTTPConnection('api.fanyi.baidu.com')
httpClient.request('GET', myurl)
# response是HTTPResponse对象
response = httpClient.getresponse()
result_all = response.read().decode("utf-8")
result = json.loads(result_all)
return result["trans_result"][0]["dst"]
except Exception as e:
print(e)
return ""
# print(etoc("china")) #单元测试
with open("inflection.py","r") as f,open("D:\\md\\b.txt","w") as fw:
for line in f.readlines():
fw.write(line.lstrip()+'\n')
file = open("D:\\md\\b.txt","rb")
newfile = open("inflection_cn.py","wb")
newfile.write("##########\r\n".encode("utg-8"))
newfile.write("#机器学习-微信:qxskying\r\n".encode("utg-8"))
newfile.write("#QQ:2375184137\r\n".encode("utg-8"))
newfile.write("##########\r\n".encode("utg-8"))
# print(file.read())
while True:
line = file.readline()
if not line:
break
line=line.decode("utf-8")
# line.lstrip()
if line[0] == "#":
print(line,end="")
print("#"+etoc(line[1:])+"\r\n",end="")
newfile.write(("#"+etoc(line[1:])+"\r\n").encode("utf-8"))
else:
print(line,end="")
newfile.write(line.encode("utf-8"))
file.close()
newfile.close()
备注:
appid = '' # 填写你的appid
secretKey = '' # 填写你的密钥
需要到百度ai上获取,或者直接在被人放出来的类似文件里获得
文件地址自己选择地方放,文件格式也一样
(2)加强版,pdf版
略。
(3)试用版,可以面向各种格式的版本
略。
(4)商用版,混用数据库,前端,后台等的,工具版本。
略。
(5)进化版本,可以盈利,可对接版本。
略。
(6)中级进化版本
略。