forked from doxxx/lodestone-recipe-db-scraper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_other_lang.py
37 lines (31 loc) · 1.05 KB
/
add_other_lang.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
import json
import sys
CLASSES = [
"Carpenter",
"Blacksmith",
"Armorer",
"Goldsmith",
"Leatherworker",
"Weaver",
"Alchemist",
"Culinarian",
]
def main():
additional_languages = {}
for arg in sys.argv[1:]:
lang, path = arg.split("=", 2)
with open(path, mode="rt", encoding="utf-8") as fp:
print(f"Loading additional language '{lang}' from: {path}")
additional_languages[lang] = json.load(fp)
for cls in CLASSES:
with open(f"out/{cls}.json", mode="rt", encoding="utf-8") as fp:
recipes = json.load(fp)
for recipe in recipes:
for lang in additional_languages.keys():
names = additional_languages[lang]
english_name = recipe['name']['en']
recipe['name'][lang] = names.get(english_name) or english_name
with open(f"out/{cls}.json", mode="wt", encoding="utf-8") as db_file:
json.dump(recipes, db_file, indent=2, sort_keys=True, ensure_ascii=False)
if __name__ == '__main__':
main()