Compare commits

1 Commits

Author SHA1 Message Date
huxiaoshuang
216cb4be52 '处理key值得字符串长度' 2022-11-23 10:54:11 +08:00
3 changed files with 25 additions and 8 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -6,6 +6,7 @@ import os
import re import re
import time import time
from tclient import tenTrans from tclient import tenTrans
from pypinyin import pinyin, lazy_pinyin, Style
def getinfo(oldWord): def getinfo(oldWord):
print('查询多语言------------------------ ') print('查询多语言------------------------ ')
@@ -37,9 +38,19 @@ def transI18(oldWord:str,newWord:str,Idword:str):
try: try:
# newkey=newWord.replace(' ','-') +'-'+str(random.randint(1,10000) ) # newkey=newWord.replace(' ','-') +'-'+str(random.randint(1,10000) )
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: 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) print('生成key: ',newkey)
r = getinfo(oldWord) r = getinfo(oldWord)
newlist=r.json()["data"] newlist=r.json()["data"]
@@ -62,20 +73,26 @@ def transI18(oldWord:str,newWord:str,Idword:str):
else: else:
pass pass
# print('数据库不存在------------------------ ') # print('数据库不存在------------------------ ')
#post新增接口
if newWord!='None' :
r =postData(oldWord,newWord,newkey)
print('post----',r.json())
if oldWord not in itemArr: if oldWord not in itemArr:
print('数据库不存在------------------------ ') print('数据库不存在------------------------ ')
#post新增接口 #post新增接口
# r =postData(oldWord,newWord,Idword,newkey) if newWord != None:
print('newWord',newWord)
r =postData(oldWord,newWord,Idword,newkey)
else:
print('请检查代理是否关闭')
else: else:
# print('没有查询结果') # print('没有查询结果')
#post新增接口 #post新增接口
newWord!='None' : if newWord != None:
print('newWord',newWord)
r =postData(oldWord,newWord,Idword,newkey) r =postData(oldWord,newWord,Idword,newkey)
else:
print('请检查代理是否关闭')
# print('即将替换的key值------------------------ ',newkey) # print('即将替换的key值------------------------ ',newkey)
return newkey return newkey