-
Notifications
You must be signed in to change notification settings - Fork 10
/
extract_avatars.py
41 lines (33 loc) · 1.1 KB
/
extract_avatars.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
import glob
import json
import argparse
import os
import re
from multiprocessing import Pool
from utils import GenshinLoader
def single_process(file, args):
lang = re.search("TextMap(?P<lang>[A-Z]+).json$", file)["lang"]
# load genshin data
genshin = GenshinLoader(repo=args.repo, lang=lang)
# output avatar
output_dir = "extracted_avatar"
output_file = os.path.join(output_dir, "avatar_{}.json".format(lang))
with open(output_file, "w", encoding="utf-8") as f:
json_file = json.dumps(
genshin.map_avatar_to_info, sort_keys=True, indent=4, ensure_ascii=False
)
print(json_file, file=f)
print("Output avatar at {}".format(output_file))
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"--repo",
default="../AnimeGameData",
type=str,
# required=True,
help="data dir",
)
args = parser.parse_args()
files = list(glob.iglob(os.path.join(args.repo, "TextMap/TextMap*.json")))
pool = Pool(10)
pool.starmap(single_process, [[file, args] for file in files])