import yaml print("PIS Module imported") def load(): # Programatically add a `toc` field to each entry. with open("/app/data/pis/gwr.yaml", "r") as data: try: pis = yaml.safe_load(data) print(pis) return pis["pis"] except yaml.YAMLError as exc: print(exc) return exc ## Do some magic here so that if any pis["pis"]["stops"][0] field contains 'reverse' then get the stops for the code stored in pis["pis"]["stops"][1] ## reverse the stops and store that. def parse(codeList): StartLen = len(codeList) print(f"pis.parse: codeList starting length: {StartLen}") for i in codeList: stops = i['stops'] code = i['code'] for ii in codeList: if stops == ii['stops'] and code != ii['code']: print(f"Identical stopping pattern found: {ii['code']}") codeList.remove(ii) print(f"pis.parse: Removed {StartLen - len(codeList)} duplicates") return codeList def devLoad(): # Programatically add a `toc` field to each entry. with open("/home/fred.boniface/git/owlboard/db-manager/data/pis/gwr.yaml", "r") as data: try: pis = yaml.safe_load(data) print(pis) return pis["pis"] except yaml.YAMLError as exc: print(exc) return exc def dev(): data = devLoad() parse(data)