代码拉取完成,页面将自动刷新
import re
import json
from utils import *
# load translation dict from ggpk file
def loadCsv(filePathName:str):
with open(filePathName, 'r', encoding='utf8') as load_f:
return load_f.read().splitlines()
def elem(line:str):
ref = re.match(r'^Metadata.*?(?=,)',line)
name = re.search(r'(?<=",\d,\d,").*(?=",Metadata)', line)
if name == None:
name = re.search(r'(?<=",\d,\d,).*(?=,Metadata)', line)
return (ref.group(), name.group())
def itemsWithLines(lines:list):
lines.pop(0) # get rid of First line because it's usless
if lines[-1] == "" : lines.pop()
return dict(elem(line) for line in lines)
def loadGgpkItems():
enDict = itemsWithLines(loadCsv("./Res/PoeItemData/en/BaseItemTypes.csv"))
cnDict = itemsWithLines(loadCsv("./Res/PoeItemData/cn/BaseItemTypes.csv"))
return {enDict[key]:cnDict[key] for key in cnDict if enDict.get(key)}
# load translation dict from poedb trade api file
def loadPoedbTradeItems() -> dict:
with open("./Res/locales/zh_CN/trade.json", 'r', encoding='utf8') as load_f:
items = json.load(load_f)
return {item["us"]:item["lang"] for item in items}
#
def loadTranslatedItems() -> dict:
with open("./Res/locales/zh_CN/items.ndjson", 'r', encoding='utf8') as load_f:
items = ndJsonToJson(load_f.read())
return {item["refName"]:item["name"] for item in items}
def loadTemplateItems() -> dict:
with open("./Res/items.ndjson", 'r', encoding='utf8') as load_f:
return ndJsonToJson(load_f.read())
# merge all translation dicts to one dict
def mergeItems():
ggpkDict = loadGgpkItems()
poeDbDict = loadPoedbTradeItems()
translatedDict = loadTranslatedItems()
return translatedDict | poeDbDict | ggpkDict
def createTradeItemsCacheFile(langTag:str):
items = mergeItems()
fileNamePath = localesFilePath + LANGUAGE_DICT[langTag] + "/itemsCache.json"
with open(fileNamePath, 'w', encoding='utf8') as save_f:
save_f.write(json.dumps(items, ensure_ascii=False, separators=(',\n', ':')))
print('File saved:', fileNamePath)
if __name__ == '__main__':
createTradeItemsCacheFile('lang "Simplified Chinese"')
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。