This repository has been archived on 2024-11-02. You can view files and clone it, but cannot push or open issues or pull requests.
db-manager/src/pis.py

43 lines
1.4 KiB
Python
Raw Normal View History

2023-05-08 19:55:09 +01:00
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)