示例#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")
示例#2
0
 async def get(self, params: structs.Params) -> Response:
     """Returns reports along a flight path"""
     stations = await FlightRouter().fetch("station", params.distance, params.route)
     resp = []
     for icao in stations:
         with suppress(BadStation):
             resp.append(asdict(Station.from_icao(icao)))
     resp = {
         "meta": handle.MetarHandler().make_meta(),
         "route": params.route,
         "results": resp,
     }
     return self.make_response(resp, params.format)
示例#3
0
def MultiStation(values: str) -> list[Station]:
    """Validates a comma-separated list of station idents"""
    values = values.upper().split(",")
    if not values:
        raise Invalid("Could not find any stations in the request")
    if len(values) > 10:
        raise Invalid("Multi requests are limited to 10 stations or less")
    ret = []
    for icao in values:
        try:
            ret.append(Station.from_icao(icao))
        except BadStation as exc:
            raise Invalid(f"{icao} is not a valid ICAO station ident") from exc
    return ret
示例#4
0
def MultiStation(stations: str) -> [Station]:
    """
    Validates a comma-separated list of station idents
    """
    stations = stations.upper().split(",")
    if not stations:
        raise Invalid("Could not find any stations in the request")
    if len(stations) > 10:
        raise Invalid("Multi requests are limited to 10 stations or less")
    ret = []
    for stn in stations:
        try:
            ret.append(Station.from_icao(stn))
        except BadStation:
            raise Invalid(f"{stn} is not a valid ICAO station ident")
    return ret
示例#5
0
def to_coordinates(values: list[Union[Coord, str]],
                   last_value: Optional[list[Coord]] = None) -> list[Coord]:
    """Convert any known idents found in a flight path into coordinates"""
    if not values:
        return values
    coord = values[0]
    if isinstance(coord, str):
        try:
            station = Station.from_icao(coord)
            coord = (station.latitude, station.longitude)
        except BadStation:
            coords = NAVAIDS[coord]
            if len(coords) == 1:
                coord = coords[0]
            else:
                new_coords = to_coordinates(values[1:], coords)
                new_coord = new_coords[0] if new_coords else None
                coord = _best_coord(last_value, coords, new_coord)
                return [coord] + new_coords
    return [coord] + to_coordinates(values[1:], coord)
示例#6
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")
示例#7
0
def to_coordinates(values: list[Union[Coord, str]],
                   last_value: Optional[list[Coord]] = None) -> list[Coord]:
    """Convert any known idents found in a flight path into coordinates"""
    if not values:
        return values
    coord = values[0]
    if isinstance(coord, str):
        try:
            # No IATA due to navaid conflict
            station = Station.from_icao(coord)
            coord = (station.latitude, station.longitude)
        except BadStation:
            coords = NAVAIDS.get(coord)
            if coords is None:
                # pylint: disable=raise-missing-from
                raise Invalid(f"Could not find coordinates for {coord}")
            if len(coords) == 1:
                coord = coords[0]
            else:
                new_coords = to_coordinates(values[1:], coords)
                new_coord = new_coords[0] if new_coords else None
                coord = _best_coord(last_value, coords, new_coord)
                return [coord] + new_coords
    return [coord] + to_coordinates(values[1:], coord)
示例#8
0
    def __init__(self, ident, index):
        self.idnet = ident
        self.index = index

        self.station = Station.from_icao(ident)
示例#9
0
def _station_for(code: str) -> Station:
    if len(code) == 3:
        return Station.from_iata(code)
    return Station.from_icao(code)