-
Notifications
You must be signed in to change notification settings - Fork 1
/
dota2schema.py
85 lines (79 loc) · 3.02 KB
/
dota2schema.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# -*- coding: UTF-8 -*-
import sys, os, requests, json, vdf
apikey = sys.argv[1]
defindexes = []
res = requests.get('https://api.steampowered.com/ISteamEconomy/GetAssetPrices/v1/?appid=570&key='+apikey)
res = json.loads(res.text)
for d in res["result"]["assets"]:
if d["prices"]["USD"] != 0:
defindexes.append(d["name"])
schema = []
itemsGame = vdf.load(open('items_game.txt', encoding='utf8'), mapper=dict)
items = itemsGame["items_game"]["items"]
for dindex in defindexes:
if dindex not in items:
items[dindex] = {
"name": "#Unknown",
"item_name": "",
"item_description": ""
}
if "item_description" not in items[dindex]:
items[dindex]["item_description"] = ""
item = {
"name": items[dindex]["name"],
"defindex": dindex,
"item_name": items[dindex]["item_name"],
"item_description": items[dindex]["item_description"]
}
schema.append(item)
# languageEN = json.load(open('items_english.json', encoding='utf8'))["lang"]["Tokens"]
languageEN = vdf.load(open('items_english.txt', encoding='utf8'), mapper=dict)["lang"]["Tokens"]
languageEN = dict((k.lower(), v) for k, v in languageEN.items())
outputEN = {"result": {"items": []}}
for item in schema:
itemName = languageEN[item["item_name"][1:].lower()] if item["item_name"][1:].lower() in languageEN else item["item_name"]
itemDesc = languageEN[item["item_description"][1:].lower()] if item["item_description"][1:].lower() in languageEN else item["item_description"]
if item["name"] == "#Unknown":
itemName = "Unknown item " + item["defindex"]
name = item["defindex"]
else:
name = item["name"]
tItem = {
"name": name,
"defindex": item["defindex"],
"item_name": itemName,
"item_description": itemDesc
}
outputEN["result"]["items"].append(tItem)
languageCN = vdf.load(open('items_english.txt', encoding='utf8'), mapper=dict)["lang"]["Tokens"]
languageCN = dict((k.lower(), v) for k, v in languageCN.items())
outputCN = {"result": {"items": []}}
for item in schema:
if item["item_name"][1:].lower() in languageCN:
itemName = languageCN[item["item_name"][1:].lower()]
elif item["item_name"][1:].lower() in languageEN:
itemName = languageEN[item["item_name"][1:].lower()]
else:
itemName = item["item_name"]
if item["item_description"][1:].lower() in languageCN:
itemDesc = languageCN[item["item_description"][1:].lower()]
elif item["item_description"][1:].lower() in languageEN:
itemDesc = languageEN[item["item_description"][1:].lower()]
else:
itemDesc = item["item_description"]
if item["name"] == "#Unknown":
itemName = "未知物品 " + item["defindex"]
name = item["defindex"]
else:
item["name"]
tItem = {
"name": name,
"defindex": item["defindex"],
"item_name": itemName,
"item_description": itemDesc
}
outputCN["result"]["items"].append(tItem)
with open('schema_en-US.json', 'w', encoding='utf-8') as f:
f.write(json.dumps(outputEN, ensure_ascii=False))
with open('schema_zh-CN.json', 'w', encoding='utf-8') as f:
f.write(json.dumps(outputCN, ensure_ascii=False))