Skip to content

Commit aed4509

Browse files
committed
Update data update merging, passing tests
1 parent 5e69850 commit aed4509

File tree

12 files changed

+1654744
-327104
lines changed

12 files changed

+1654744
-327104
lines changed

avwx/data/build_aircraft.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ def main() -> int:
2525
for row in rows:
2626
cols = row.split("\n")
2727
name = TAG_PATTERN.sub("", cols[3]).strip()
28-
if "deprecated" in name:
28+
if not name or "deprecated" in name:
2929
continue
3030
code = TAG_PATTERN.sub("", cols[1]).strip()
3131
if code not in craft:
3232
craft[code] = name
3333
old_craft = json.load(OUTPUT_PATH.open(encoding="utf8"))
34-
json.dump(old_craft | craft, OUTPUT_PATH.open("w", encoding="utf8"))
34+
json.dump(old_craft | craft, OUTPUT_PATH.open("w", encoding="utf8"), sort_keys=True, indent=1)
3535
return 0
3636

3737

avwx/data/build_navaids.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ def main() -> None:
2828
data[ident].add((lat, lon))
2929
except KeyError:
3030
data[ident] = {(lat, lon)}
31-
output = {k: list(v) for k, v in data.items()}
32-
json.dump(output, OUTPUT_PATH.open("w"), sort_keys=True)
31+
with OUTPUT_PATH.open(encoding="utf8") as fin:
32+
output = json.load(fin)
33+
output |= {k: list(v) for k, v in data.items()}
34+
json.dump(output, OUTPUT_PATH.open("w", encoding="utf8"), sort_keys=True, indent=1)
3335

3436

3537
if __name__ == "__main__":

avwx/data/build_stations.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,9 @@ def format_station(code: str, station: list[str]) -> dict:
148148

149149
def build_stations() -> tuple[dict, dict]:
150150
"""Build the station dict from source file."""
151-
stations, code_map = {}, {}
151+
code_map = {}
152+
with OUTPUT_PATH.open(encoding="utf8") as fin:
153+
stations = json.load(fin)
152154
data = csv.reader(_SOURCE["airports"].splitlines())
153155
next(data) # Skip header
154156
for station in data:
@@ -170,6 +172,11 @@ def get_surface_type(surface: str) -> str | None:
170172
return next((key for key, items in SURFACE_TYPES.items() if surface in items), None)
171173

172174

175+
def has_runways(station: dict) -> bool:
176+
"""Check if the station has runway information."""
177+
return "runways" in station and station["runways"] is not None
178+
179+
173180
def add_runways(stations: dict, code_map: dict) -> dict:
174181
"""Add runway information to station if availabale."""
175182
data = csv.reader(_SOURCE["runways"].splitlines())
@@ -190,13 +197,13 @@ def add_runways(stations: dict, code_map: dict) -> dict:
190197
}
191198
code = code_map.get(runway[1], runway[2])
192199
with suppress(KeyError):
193-
if "runways" in stations[code]:
200+
if has_runways(stations[code]):
194201
stations[code]["runways"].append(out)
195202
else:
196203
stations[code]["runways"] = [out]
197204
# Sort runways by longest length and add missing nulls
198205
for code in stations:
199-
if "runways" in stations[code]:
206+
if has_runways(stations[code]):
200207
stations[code]["runways"].sort(key=lambda x: x["length_ft"], reverse=True)
201208
else:
202209
stations[code]["runways"] = None
@@ -252,13 +259,8 @@ def update_station_info_date() -> None:
252259

253260
def save_station_data(stations: dict) -> None:
254261
"""Save stations to JSON package data."""
255-
json.dump(
256-
stations,
257-
OUTPUT_PATH.open("w", encoding="utf8"),
258-
sort_keys=True,
259-
indent=1,
260-
ensure_ascii=False,
261-
)
262+
with OUTPUT_PATH.open("w", encoding="utf8") as fout:
263+
json.dump(stations, fout, sort_keys=True, indent=1, ensure_ascii=False)
262264

263265

264266
def main() -> int:

avwx/data/files/aircraft.json

Lines changed: 345 additions & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)