forked from ROBOT-IS-CHILL/robot-is-chill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert-json.py
38 lines (29 loc) · 1.1 KB
/
convert-json.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
import tomlkit
import glob
from pathlib import Path
from src.types import TilingMode
def main():
for path in glob.glob("data/custom/*.toml"):
path = Path(path)
print(f"Reserializing {path}...")
with open(path, "r") as file:
tiles = {key: value for key, value in tomlkit.load(file).items()}
doc = tomlkit.document()
doc.add(tomlkit.comment("See CONTRIBUTING.md for how to properly edit this file."))
doc.add(tomlkit.nl())
doc.add(tomlkit.nl())
doc.add(tomlkit.nl())
for name, data in tiles.items():
if data["tiling"] == +TilingMode.TILING and data.pop("diagonal"):
data["tiling"] = +TilingMode.DIAGONAL_TILING
data["tiling"] = str(TilingMode(data["tiling"]))
table = tomlkit.inline_table()
table.update(data)
doc.add(name, table)
doc.add(tomlkit.nl())
toml_path = path.with_suffix(".toml")
with open(toml_path, "w+") as file:
tomlkit.dump(doc, file)
print("Done.")
if __name__ == "__main__":
main()