avwx.data

Certain components of AVWX rely on data files compiled from remote sources that should be kept up to date. This includes:

  • Station information database
  • Navigation aids
  • Aircraft codes

While these are updated on a regular basis with point updates, you may wish to update them on a more frequent basis. As of version 1.7 of the library, you can do this manually with the data module.

>>> from avwx.data import update_all
>>> update_all()
True

This updates all package data files and avwx.station.meta.__STATIONS_UPDATED__ date. Due to how this data is managed, you should only run updates prior to starting your primary Python application. Doing so during an existing run may still use old data depending on the architecture of your program.

 1"""
 2Certain components of AVWX rely on data files compiled from remote sources that
 3should be kept up to date. This includes:
 4
 5- Station information database
 6- Navigation aids
 7- Aircraft codes
 8
 9While these are updated on a regular basis with point updates, you may wish to
10update them on a more frequent basis. As of version 1.7 of the library, you can
11do this manually with the `data` module.
12
13```python
14>>> from avwx.data import update_all
15>>> update_all()
16True
17```
18
19This updates all package data files and
20`avwx.station.meta.__STATIONS_UPDATED__` date. Due to how this data is managed,
21you should only run updates prior to starting your primary Python application.
22Doing so during an existing run may still use old data depending on the
23architecture of your program.
24"""
25
26# from avwx.data.build_aircraft import main as update_aircraft
27from avwx.data.build_navaids import main as update_navaids
28from avwx.data.build_stations import main as update_stations
29
30
31def update_all() -> bool:
32    """Update all local data. Requires a reimport to guarentee update"""
33    return not any(func() for func in (update_navaids, update_stations))
34
35
36__all__ = ["update_all", "update_navaids", "update_stations"]
37
38
39if __name__ == "__main__":
40    update_all()
def update_all() -> bool:
32def update_all() -> bool:
33    """Update all local data. Requires a reimport to guarentee update"""
34    return not any(func() for func in (update_navaids, update_stations))

Update all local data. Requires a reimport to guarentee update

def update_navaids() -> None:
16def main() -> None:
17    """Builds the navaid coordinate map"""
18    text = httpx.get(URL).text
19    lines = text.strip().split("\n")
20    lines.pop(0)
21    data: Dict[str, Set[Tuple[float, float]]] = {}
22    for line_str in lines:
23        line = line_str.split(",")
24        try:
25            ident, lat, lon = line[2].strip('"'), float(line[6]), float(line[7])
26        except ValueError:
27            continue
28        if not ident:
29            continue
30        try:
31            data[ident].add((lat, lon))
32        except KeyError:
33            data[ident] = {(lat, lon)}
34    output = {k: list(v) for k, v in data.items()}
35    json.dump(output, OUTPUT_PATH.open("w"), sort_keys=True)

Builds the navaid coordinate map

def update_stations() -> int:
261def main() -> int:
262    """Build/update the stations.json main file"""
263    LOG.info("Fetching")
264    if not download_source_files():
265        LOG.error("Unable to update source files")
266        return 1
267    check_local_icaos()
268    check_local_awos()
269    LOG.info("Cleaning")
270    clean_source_files()
271    LOG.info("Building")
272    load_codes()
273    stations, code_map = build_stations()
274    stations = add_missing_stations(stations)
275    stations = add_reporting(stations)
276    stations = add_runways(stations, code_map)
277    LOG.info("Saving")
278    save_station_data(stations)
279    LOG.info("Updating station date")
280    update_station_info_date()
281    return 0

Build/update the stations.json main file