Make worker.val JSON compatible

This commit is contained in:
Klaus-Uwe Mitterer 2017-09-24 21:04:59 +02:00
parent dbed1fa677
commit b8b233f630
2 changed files with 10 additions and 3 deletions

View file

@ -70,6 +70,7 @@ def worker(lat, lon, distance = 1000, json = False):
outtext += ",\n" if (json and not outtext.strip()[-1] == "[") else ""
station.distance = station.distance or int(cDistance(station.lat(), station.lon(), lat, lon))
outtext += station.json(2, distance = True) if json else station.xml(1, distance = True)
outtext += "\n" if not json else ""
outtext += """
]

View file

@ -22,14 +22,20 @@ def validateName(name):
yield Station(name = name, sttype = sttype, extid = extid, xcoord = xcoord, ycoord = ycoord, prodclass = prodclass)
def worker(name, json = False):
outtext = """<?xml version="1.0" encoding="UTF-8"?>
outtext = """{
"stations": [
""" if json else """<?xml version="1.0" encoding="UTF-8"?>
<stations>
"""
for station in validateName(name):
outtext += station.xml(1)
outtext += ",\n" if (json and not outtext.strip()[-1] == "[") else ""
outtext += station.json(2) if json else station.xml(1)
outtext += "\n" if not json else ""
outtext += "</stations>"
outtext += """
]
}""" if json else "</stations>"
return outtext