def valid_station(station: str): """Checks the validity of a station ident This function doesn't return anything. It merely raises a BadStation error if needed """ station = station.strip() if len(station) != 4: raise BadStation("ICAO station ident must be four characters long") uses_na_format(station)
def from_icao(cls, ident: str) -> "Station": """Load a Station from an ICAO station ident""" try: info = copy(_STATIONS[ident.upper()]) if info["runways"]: info["runways"] = [Runway(**r) for r in info["runways"]] return cls(**info) except (KeyError, AttributeError) as not_found: raise BadStation( f"Could not find station with ident {ident}") from not_found
def from_icao(cls, ident: str) -> 'Station': """ Load a Station from an ICAO station ident """ if not ident in STATIONS: raise BadStation( 'Could not find station in the info dict. Check avwx.structs.STATIONS' ) info = copy(STATIONS[ident]) if info['runways']: info['runways'] = [Runway(**r) for r in info['runways']] return cls(**info)
def from_icao(cls, ident: str) -> "Station": """ Load a Station from an ICAO station ident """ if ident not in STATIONS: raise BadStation( "Could not find station in the info dict. Check avwx.structs.STATIONS" ) info = copy(STATIONS[ident]) if info["runways"]: info["runways"] = [Runway(**r) for r in info["runways"]] return cls(**info)
def station_info(self): """ Provide basic station info """ if self._station_info is None: if not self.station in STATIONS: raise BadStation( 'Could not find station in the info dict. Check avwx.STATIONS' ) info = [self.station] + STATIONS[self.station] self._station_info = dict(zip(INFO_KEYS, info)) return self._station_info
def uses_na_format(station: str) -> bool: """Returns True if the station uses the North American format, False if the International format """ if station[0] in NA_REGIONS: return True if station[0] in IN_REGIONS: return False if station[:2] in M_NA_REGIONS: return True if station[:2] in M_IN_REGIONS: return False raise BadStation("Station doesn't start with a recognized character set")
def station_info(self) -> dict: """ Provide basic station info Raises a BadStation exception if the station's info cannot be found """ if self._station_info is None: if not self.station in STATIONS: raise BadStation( 'Could not find station in the info dict. Check avwx.STATIONS' ) info = [self.station] + STATIONS[self.station] self._station_info = dict(zip(INFO_KEYS, info)) return self._station_info