小鑫降重软件开源

本文最后更新于:2022年7月9日 下午

小鑫降重软件开源

成品展示

upload successful

主程序main.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# author :Liansixin
import hashlib
import http
import json
import sys
import random
import os
import urllib
import requests
from translate import Translator
import http.client
import hashlib
import urllib
import random
import json

if hasattr(sys, 'frozen'):
os.environ['PATH'] = sys._MEIPASS + ";" + os.environ['PATH']

from mainWindow import Ui_MainWindow
from PyQt5.Qt import *


class MyWindow(QMainWindow, Ui_MainWindow):

def __init__(self, parent=None):
super(MyWindow, self).__init__(parent)
self.setupUi(self)
self.pushButton.clicked.connect(self.click_pushButton)

def click_pushButton(self):
tst = self.textEdit.toPlainText()
tst = youdao_en(tst)
print(tst)
translation = trans_lang(tst)
print(translation)
self.textEdit_2.setText(translation)
return


def youdao_en(query):
url = 'http://fanyi.youdao.com/translate'
data = {
"i": query, # 待翻译的字符串
"from": "zh-CHS",
"to": "en",
"smartresult": "dict",
"client": "fanyideskweb",
"salt": "16081210430989",
"doctype": "json",
"version": "2.1",
"keyfrom": "fanyi.web",
"action": "FY_BY_CLICKBUTTION"
}
res = requests.post(url, data=data).json()
return res['translateResult'][0][0]['tgt']

def trans_lang(q):
trans_result = q
# 百度appid和密钥需要通过注册百度【翻译开放平台】账号后获得
appid = '20211103000990117' # 填写你的appid
secretKey = 'LXQgIXAj9aoKoHGMA7zs' # 填写你的密钥

httpClient = None
myurl = '/api/trans/vip/translate' # 通用翻译API HTTP地址

fromLang = 'auto' # 原文语种
toLang = 'zh' # 译文语种
salt = random.randint(32768, 65536)
# 手动录入翻译内容,q存放
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)
trans_result = result['trans_result'][0]['dst']
except Exception as e:
print(e)
finally:
if httpClient:
httpClient.close()
return trans_result

if __name__ == '__main__':
app = QApplication(sys.argv)
show = MyWindow()
show.show()
sys.exit(app.exec_())


视图实现mainWindow.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# author :Liansixin

import os
import sys
from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(1059, 431)
self.centralWidget = QtWidgets.QWidget(MainWindow)
self.centralWidget.setObjectName("centralWidget")
self.textEdit = QtWidgets.QTextEdit(self.centralWidget)
self.textEdit.setGeometry(QtCore.QRect(110, 60, 321, 291))
self.textEdit.setLocale(QtCore.QLocale(QtCore.QLocale.Chinese, QtCore.QLocale.China))
self.textEdit.setObjectName("textEdit")
self.textEdit_2 = QtWidgets.QTextEdit(self.centralWidget)
self.textEdit_2.setGeometry(QtCore.QRect(600, 60, 321, 291))
self.textEdit_2.setLocale(QtCore.QLocale(QtCore.QLocale.Chinese, QtCore.QLocale.China))
self.textEdit_2.setObjectName("textEdit_2")
self.pushButton = QtWidgets.QPushButton(self.centralWidget)
self.pushButton.setGeometry(QtCore.QRect(460, 190, 101, 61))
self.pushButton.setObjectName("pushButton")
self.label = QtWidgets.QLabel(self.centralWidget)
self.label.setGeometry(QtCore.QRect(240, 20, 41, 31))
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(self.centralWidget)
self.label_2.setGeometry(QtCore.QRect(750, 30, 41, 16))
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(self.centralWidget)
self.label_3.setGeometry(QtCore.QRect(430, 370, 161, 20))
self.label_3.setObjectName("label_3")
MainWindow.setCentralWidget(self.centralWidget)
self.statusBar = QtWidgets.QStatusBar(MainWindow)
self.statusBar.setObjectName("statusBar")
MainWindow.setStatusBar(self.statusBar)

self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)

def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "小鑫降重工具"))
self.pushButton.setText(_translate("MainWindow", "开始降重"))
self.label.setText(_translate("MainWindow", "原文"))
self.label_2.setText(_translate("MainWindow", "结果"))
self.label_3.setText(_translate("MainWindow", "该工具使用需要联网哦"))

开源库地址:

https://github.com/JinBiLianShao/XiaoxinPaper

点我访问


小鑫降重软件开源
https://jinbilianshao.github.io/2022/06/05/小鑫降重软件开源/
作者
连思鑫
发布于
2022年6月5日
许可协议