Beispiel #1
0
 def validator(loc: str) -> Station:
     loc = loc.upper().split(",")
     if len(loc) == 1:
         icao = loc[0]
         try:
             return Station.from_icao(icao)
         except BadStation:
             if icao in ICAO_WHITELIST:
                 return Station(*([None] * 4), "DNE", icao, *([None] * 9))
             raise Invalid(f"{icao} is not a valid ICAO station ident")
     elif len(loc) == 2:
         try:
             lat, lon = Latitude(loc[0]), Longitude(loc[1])
             if coerce_station:
                 return Station.nearest(lat, lon)[0]
             return lat, lon
         except:
             raise Invalid(f"{loc} is not a valid coordinate pair")
     else:
         raise Invalid(f"{loc} is not a valid station/coordinate pair")
Beispiel #2
0
 def validator(loc: str) -> Station:
     loc = loc.upper().split(",")
     if len(loc) == 1:
         code = loc[0]
         try:
             return _station_for(code)
         except BadStation as exc:
             # if icao in ICAO_WHITELIST:
             #     return Station(*([None] * 4), "DNE", icao, *([None] * 9))
             raise Invalid(f"{code} is not a valid ICAO or IATA code") from exc
     elif len(loc) == 2:
         try:
             lat, lon = Latitude(loc[0]), Longitude(loc[1])
             if coerce_station:
                 return Station.nearest(
                     lat, lon, is_airport=airport, sends_reports=reporting
                 )[0]
             return lat, lon
         except Exception as exc:
             raise Invalid(f"{loc} is not a valid coordinate pair") from exc
     else:
         raise Invalid(f"{loc} is not a valid station/coordinate pair")