element-themes/build.py

68 lines
1.5 KiB
Python
Raw Normal View History

2020-06-07 06:37:56 +02:00
#!/usr/bin/python
# This takes all the themes and puts it in one file
import json
import os
OUTPUT = "./output.json"
BLACKLIST = [
".git",
"images"
]
if __name__ == '__main__':
result = []
json_paths = []
2020-06-07 06:41:18 +02:00
# 1. Let's recursively look for all the JSON files
2020-06-07 06:37:56 +02:00
# root_dirs = ["Discord", "Geeko Dark", etc...]
root = os.listdir("./")
for root_dir in root:
is_dir = os.path.isdir(f"./{root_dir}")
2020-06-07 06:41:18 +02:00
if root_dir in BLACKLIST or not is_dir:
2020-06-07 06:37:56 +02:00
continue
2020-06-07 06:41:18 +02:00
2020-06-07 06:37:56 +02:00
2020-06-07 06:41:18 +02:00
# if root_dir is "Discord" then deep_dirs is
2020-06-07 06:37:56 +02:00
# deep_dirs = ["Discord-Dark"]
2020-06-07 06:41:18 +02:00
# ./Discord
# └── Discord-Dark
# ├── Discord-Dark-Theme.json
# └── Discord-Dark-Theme.png
2020-06-07 06:37:56 +02:00
deep_dirs = os.listdir(f"./{root_dir}")
for deep in deep_dirs:
current_path = f"./{root_dir}/{deep}"
is_dir = os.path.isdir(current_path)
if is_dir:
files = os.listdir(current_path)
for file in files:
current_path = f"./{root_dir}/{deep}/{file}"
if file.lower().endswith(".json"):
json_paths.append(current_path)
print(f"Added {file}")
elif deep.lower().endswith(".json"):
json_paths.append(current_path)
print(f"Added {file}")
2020-06-07 06:37:56 +02:00
2020-06-07 06:41:18 +02:00
# 2. Now let's parse all the JSON files
2020-06-07 06:37:56 +02:00
for json_path in json_paths:
with open(json_path, 'r') as file:
parsed = json.load(file)
result.append(parsed)
2020-06-07 06:41:18 +02:00
# 3. Finally output the themes as a JSON array
2020-06-07 06:37:56 +02:00
with open(OUTPUT, 'w') as output:
output.write(
json.dumps(result, indent=2)
)
output.close()
print(f"Output: {OUTPUT}")