diff --git a/__pycache__/BaiduTrans.cpython-39.pyc b/__pycache__/BaiduTrans.cpython-39.pyc new file mode 100644 index 0000000..51e57d8 Binary files /dev/null and b/__pycache__/BaiduTrans.cpython-39.pyc differ diff --git a/__pycache__/tclient.cpython-39.pyc b/__pycache__/tclient.cpython-39.pyc new file mode 100644 index 0000000..0e059cd Binary files /dev/null and b/__pycache__/tclient.cpython-39.pyc differ diff --git a/trans.py b/trans.py index 2987a3c..2d3b0e7 100644 --- a/trans.py +++ b/trans.py @@ -6,6 +6,7 @@ import os import re import time from tclient import tenTrans +from pypinyin import pinyin, lazy_pinyin, Style def getinfo(oldWord): print('查询多语言------------------------ ') @@ -37,9 +38,19 @@ def transI18(oldWord:str,newWord:str,Idword:str): try: # newkey=newWord.replace(' ','-') +'-'+str(random.randint(1,10000) ) newkey=newWord.replace(' ','_') +'_'+str(random.randint(1,10000) ) # 下划线容易复制 + # 截取70个字符 + newkey=newkey[0:71] + newkey=newkey+'_'+str(random.randint(1,10000)) + except: - newkey=oldWord+'-'+str(random.randint(1,10000)) + # lazy_pinyin('中心') ['zhong', 'xin'] + newkey='_'.join(lazy_pinyin(oldWord)) +'_'+str(random.randint(1,10000)) + # 截取70个字符 + newkey=newkey[0:71] + newkey=newkey+'_'+str(random.randint(1,10000)) + + # newkey=oldWord+'-'+str(random.randint(1,10000)) print('生成key: ',newkey) r = getinfo(oldWord) newlist=r.json()["data"] @@ -62,20 +73,26 @@ def transI18(oldWord:str,newWord:str,Idword:str): else: pass # print('数据库不存在------------------------ ') - #post新增接口 - - if newWord!='None' : - r =postData(oldWord,newWord,newkey) - print('post----',r.json()) if oldWord not in itemArr: print('数据库不存在------------------------ ') #post新增接口 - # r =postData(oldWord,newWord,Idword,newkey) + if newWord != None: + print('newWord',newWord) + r =postData(oldWord,newWord,Idword,newkey) + else: + print('请检查代理是否关闭') + else: # print('没有查询结果') #post新增接口 - newWord!='None' : + if newWord != None: + print('newWord',newWord) r =postData(oldWord,newWord,Idword,newkey) + else: + print('请检查代理是否关闭') + + + # print('即将替换的key值------------------------ ',newkey) return newkey