anny-booking-automation/resource_id_helper.py

25 lines
723 B
Python
Raw Permalink Normal View History

2026-02-05 15:18:19 +01:00
import json
2026-02-07 13:50:59 +01:00
with open("data.json", "r", encoding="utf-8") as f:
2026-02-05 15:18:19 +01:00
data = json.load(f)
2026-02-07 13:50:59 +01:00
keys_to_keep = {"name"}
keys_to_keep2 = {"attributes", "id"}
2026-02-05 15:18:19 +01:00
for i in data["data"]:
2026-02-07 13:50:59 +01:00
attr = i["attributes"]
for key in list(attr.keys()):
if key not in keys_to_keep:
del attr[key]
for key in list(i.keys()):
if key not in keys_to_keep2:
del i[key]
# i["attributes"].pop("description", None) # safe remove
# i["attributes"].pop("plain_description", None) # safe remove
with open("data.json", "w") as f:
json.dump(data, f, indent=2)
# for i in data["data"]:
# print("%-32s id: %s" % (i["attributes"]["name"], i["id"]))
# print(type(data)) # usually <class 'dict'>