Closed jamesturk closed 2 years ago
import sys, glob
import yaml
def convert_file(filename):
with open(filename) as f:
data = yaml.safe_load(f)
offices = []
district_num = 1
for cd in data.pop("contact_details", []):
note = cd.pop("note")
if note == "District Office":
cd["classification"] = "district"
cd["name"] = f"District Office #{district_num}"
district_num += 1
elif note == "Capitol Office":
cd["classification"] = "capitol"
elif note == "Primary Office":
cd["classification"] = "primary"
offices.append(cd)
if offices:
data["offices"] = offices
with open(filename, "w") as f:
yaml.safe_dump(data, f, sort_keys=False)
if __name__ == "__main__":
for name in glob.glob("*/*/*/*.yml"):
print(name)
convert_file(name)
It is probably about time to get rid of the contact_details schema, which causes a lot of confusion, and instead move to an offices schema.
Problems:
Rough roadmap: