Sfoglia il codice sorgente

fix: env vars type error (#1127)

master
lanvent 1 anno fa
parent
commit
4c5e8850aa
1 ha cambiato i file con 3 aggiunte e 1 eliminazioni
  1. +3
    -1
      translate/baidu/baidu_translate.py

+ 3
- 1
translate/baidu/baidu_translate.py Vedi File

@@ -17,13 +17,15 @@ class BaiduTranslator(Translator):
self.url = endpoint + path
self.appid = conf().get("baidu_translate_app_id")
self.appkey = conf().get("baidu_translate_app_key")
if not self.appid or not self.appkey:
raise Exception("baidu translate appid or appkey not set")

# For list of language codes, please refer to `https://api.fanyi.baidu.com/doc/21`, need to convert to ISO 639-1 codes
def translate(self, query: str, from_lang: str = "", to_lang: str = "en") -> str:
if not from_lang:
from_lang = "auto" # baidu suppport auto detect
salt = random.randint(32768, 65536)
sign = self.make_md5(self.appid + query + str(salt) + self.appkey)
sign = self.make_md5("{}{}{}{}".format(self.appid, query, salt, self.appkey))
headers = {"Content-Type": "application/x-www-form-urlencoded"}
payload = {"appid": self.appid, "q": query, "from": from_lang, "to": to_lang, "salt": salt, "sign": sign}



Loading…
Annulla
Salva