2023-02-26 17:02:41 +03:00
|
|
|
import os
|
|
|
|
import json
|
|
|
|
import yaml
|
|
|
|
import hashlib
|
|
|
|
|
2023-02-27 20:43:11 +03:00
|
|
|
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"],
|
2023-02-27 21:03:49 +03:00
|
|
|
"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)
|