-
Notifications
You must be signed in to change notification settings - Fork 1
/
Bing_Translate.py
30 lines (26 loc) · 954 Bytes
/
Bing_Translate.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
import requests
import base64
class BingTranslate:
def __init__(self):
self.warning()
def warning(self):
print("De su dung bing search , chay cau lenh: 'node app.js' de bat server")
def translate(self, text):
print("Bing translate: ", text)
try:
url = "http://localhost:8989/translate"
params = {
"text": text
}
r = requests.get(url, params=params)
if r.status_code == 200 and r.text != "undefined" and r.text != "":
return base64.b64decode(r.content).decode('utf-8')
elif r.status_code == 200 and (r.text == "undefined" or r.text == ""):
print("Bing translate error: ", r.text)
return ""
else:
print("Bing translate error: ", r.status_code)
return ""
except Exception as e:
print(e)
return ""