forked from doxxx/lodestone-recipe-db-scraper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Script for adding other languages to existing output files.
This can be used to update an existing set of output files with new translations for the additional languages like Korean and Chinese, without having to rerun the main scraper script.
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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() |