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 26from 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_aircraft, update_navaids, update_stations)) 34 35 36__all__ = ["update_all", "update_aircraft", "update_navaids", "update_stations"] 37 38 39if __name__ == "__main__": 40 update_all()
32def update_all() -> bool: 33 """Update all local data. Requires a reimport to guarentee update""" 34 return not any(func() for func in (update_aircraft, update_navaids, update_stations))
Update all local data. Requires a reimport to guarentee update
17def main() -> int: 18 """Build/update aircraft.json codes.""" 19 resp = httpx.get(URL) 20 if resp.status_code != 200: 21 return 1 22 text = resp.text 23 text = text[text.find("<caption>ICAO") :] 24 rows = text[: text.find("</table>")].split("<tr>")[2:] 25 craft = {} 26 for row in rows: 27 cols = row.split("\n") 28 name = TAG_PATTERN.sub("", cols[3]).strip() 29 if "deprecated" in name: 30 continue 31 code = TAG_PATTERN.sub("", cols[1]).strip() 32 if code not in craft: 33 craft[code] = name 34 old_craft = json.load(OUTPUT_PATH.open(encoding="utf8")) 35 json.dump(old_craft | craft, OUTPUT_PATH.open("w", encoding="utf8")) 36 return 0
Build/update aircraft.json codes.
264def main() -> int: 265 """Build/update the stations.json main file.""" 266 LOG.info("Fetching") 267 if not download_source_files(): 268 LOG.error("Unable to update source files") 269 return 1 270 check_local_icaos() 271 check_local_awos() 272 LOG.info("Cleaning") 273 clean_source_files() 274 LOG.info("Building") 275 load_codes() 276 stations, code_map = build_stations() 277 stations = add_missing_stations(stations) 278 stations = add_reporting(stations) 279 stations = add_runways(stations, code_map) 280 LOG.info("Saving") 281 save_station_data(stations) 282 LOG.info("Updating station date") 283 update_station_info_date() 284 return 0
Build/update the stations.json main file.