コード例 #1
0
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)
コード例 #2
0
ファイル: station.py プロジェクト: china1885/avwx-engine
 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
コード例 #3
0
ファイル: structs.py プロジェクト: caseydubose/AVWX-Engine
 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)
コード例 #4
0
 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)
コード例 #5
0
 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
コード例 #6
0
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")
コード例 #7
0
ファイル: __init__.py プロジェクト: sheeeng/AVWX-Engine
    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