Use utf8-encoding whenever JSON is processed

This commit is contained in:
Andreas Weinzierl
2021-01-27 23:31:33 +01:00
parent b884a9c387
commit 0f7b678f57
4 changed files with 13 additions and 11 deletions

View File

@ -19,12 +19,12 @@ import json
index_path = "../web/packs/index.json"
try:
with open(index_path) as index_file:
with util.open_utf8(index_path) as index_file:
index_data = json.load(index_file)
except (FileNotFoundError, json.JSONDecodeError):
index_data = {"packs": []}
with open(sys.argv[-1]) as file:
with util.open_utf8(sys.argv[-1]) as file:
data = json.load(file)
for pack in data["assets"]:
@ -45,12 +45,12 @@ for pack in data["assets"]:
}
filename = f"scalar-{pack['name'].replace(' ', '_')}.json"
pack_path = f"web/packs/{filename}"
with open(pack_path, "w") as pack_file:
with util.open_utf8(pack_path, "w") as pack_file:
json.dump(pack_data, pack_file)
print(f"Wrote {title} to {pack_path}")
if filename not in index_data["packs"]:
index_data["packs"].append(filename)
with open(index_path, "w") as index_file:
with util.open_utf8(index_path, "w") as index_file:
json.dump(index_data, index_file, indent=" ")
print(f"Updated {index_path}")