|
1 | | -import importlib |
2 | | -import json |
3 | | -import logging |
4 | | -from pathlib import Path |
5 | | -from typing import Any, Dict |
6 | | - |
7 | | -import httpx |
8 | | - |
9 | | -import pandas as pd |
10 | | - |
11 | | -from ... import cache_expiration, cache_path |
12 | | -from .. import client |
13 | | - |
14 | | -__all__ = list(p.stem[1:] for p in Path(__file__).parent.glob("_[a-z]*py")) |
15 | | - |
16 | | -_log = logging.getLogger(__name__) |
17 | | - |
18 | | - |
19 | | -class ADDS_FAA_OpenData: |
20 | | - id_: str |
21 | | - filename: str |
22 | | - website = "https://adds-faa.opendata.arcgis.com/datasets/{}" |
23 | | - json_url = "https://opendata.arcgis.com/datasets/{}.geojson" |
24 | | - |
25 | | - def __init__(self) -> None: |
26 | | - self.cache_file = cache_path / self.filename |
27 | | - self.website = self.website.format(self.id_) |
28 | | - self.json_url = self.json_url.format(self.id_) |
29 | | - |
30 | | - def download_data(self) -> None: |
31 | | - _log.warning( |
32 | | - f"Downloading data from {self.website}. Please check terms of use." |
33 | | - ) |
34 | | - c = client.get(self.json_url) |
35 | | - c.raise_for_status() |
36 | | - json_contents = c.json() |
37 | | - with self.cache_file.open("w") as fh: |
38 | | - json.dump(json_contents, fh) |
39 | | - |
40 | | - def json_contents(self) -> Dict[str, Any]: |
41 | | - if self.cache_file.exists(): |
42 | | - last_modification = (self.cache_file).lstat().st_mtime |
43 | | - delta = pd.Timestamp("now") - pd.Timestamp(last_modification * 1e9) |
44 | | - |
45 | | - if cache_expiration is not None and delta > cache_expiration: |
46 | | - try: |
47 | | - self.download_data() |
48 | | - except httpx.TransportError: |
49 | | - pass |
50 | | - else: |
51 | | - self.download_data() |
52 | | - |
53 | | - with self.cache_file.open("r") as fh: |
54 | | - json_contents = json.load(fh) |
55 | | - |
56 | | - return json_contents # type: ignore |
57 | | - |
58 | | - |
| 1 | +from typing import Any |
| 2 | + |
| 3 | +from ._airspaces import ( |
| 4 | + Airspace_Boundary, |
| 5 | + Class_Airspace, |
| 6 | + Prohibited_Airspace, |
| 7 | + Route_Airspace, |
| 8 | + Special_Use_Airspace, |
| 9 | +) |
| 10 | +from ._ats_route import Ats_Route |
| 11 | +from ._designated_points import Designated_Points |
| 12 | +from ._navaid_components import Navaid_Components |
| 13 | + |
| 14 | +__all__ = [ |
| 15 | + "Airspace_Boundary", |
| 16 | + "Ats_Route", |
| 17 | + "Class_Airspace", |
| 18 | + "Designated_Points", |
| 19 | + "Navaid_Components", |
| 20 | + "Prohibited_Airspace", |
| 21 | + "Route_Airspace", |
| 22 | + "Special_Use_Airspace", |
| 23 | +] |
| 24 | + |
| 25 | + |
| 26 | +# this is here for compatibility with the <=2.12.0 API to allow for stuff like |
| 27 | +# `from traffic.data.faa import class_airspace` |
59 | 28 | def __getattr__(name: str) -> Any: |
60 | | - if name in __all__: |
61 | | - mod = importlib.import_module("._" + name, package="traffic.data.faa") |
62 | | - return getattr(mod, name.title())() |
| 29 | + for cls in __all__: |
| 30 | + if cls.lower() == name.lower(): |
| 31 | + return globals()[cls]() |
63 | 32 |
|
64 | 33 | raise AttributeError() |
0 commit comments