1
0
mirror of https://github.com/Mayccoll/Gogh.git synced 2023-08-10 21:12:46 +03:00
Gogh/tools/generatJson.py

40 lines
1.1 KiB
Python
Raw Normal View History

2023-02-26 17:02:41 +03:00
import os
import json
import yaml
import hashlib
source_path = "./themes"
2023-02-27 02:55:53 +03:00
dest_path = "./data/themes.json"
2023-02-26 17:02:41 +03:00
themes = []
os.remove(dest_path)
for filename in os.listdir(source_path):
if filename.endswith(".yml"):
with open(os.path.join(source_path, filename), "r") as f:
data = yaml.safe_load(f)
# Concatenate values of each key
values = ''
for key in data:
values += str(data[key])
# Generate SHA-256 hash
hash_object = hashlib.sha256(values.encode())
hash_hex = hash_object.hexdigest()
theme = {f"{key}": data[key] for key in data if key.startswith("color")}
theme.update({
"name": data["name"],
"foreground": data["foreground"],
"background": data["background"],
"cursor": data["cursor"],
2023-02-26 17:02:41 +03:00
"hash": hash_hex
})
themes.append(theme)
themes = sorted(themes, key=lambda x: x["name"])
json_data = {"themes": themes}
with open(dest_path, "w") as f:
json.dump(json_data, f)