diff --git a/README.md b/README.md index 4e7c227..3d5ea30 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,9 @@ pyoscar stations --country=CAN # get all station identifiers by program affiliation pyoscar stations --program=GAW +# get all stations by station name (partial names are supported) +pyoscar stations --station-name toronto + # get a single station by WIGOS identifier pyoscar station 0-20000-0-71151 diff --git a/pyoscar/__init__.py b/pyoscar/__init__.py index 793e70d..e9bd31a 100644 --- a/pyoscar/__init__.py +++ b/pyoscar/__init__.py @@ -92,7 +92,8 @@ def __init__(self, env: str = 'prod', api_token: str = None, self.headers['X-WMO-WMDR-Token'] = self.api_token def get_stations(self, program: str = None, country: str = None, - station_type: str = None, wigos_id: str = None) -> list: + station_name: str = None, station_type: str = None, + wigos_id: str = None) -> list: """ get all stations @@ -111,6 +112,7 @@ def get_stations(self, program: str = None, country: str = None, - seaFixed - airFixed - landOnIce + :param station_name: station name :param wigos_id: WIGOS identifier :returns: `list` of all matching stations @@ -125,6 +127,9 @@ def get_stations(self, program: str = None, country: str = None, if wigos_id is not None: LOGGER.debug(f'WIGOS ID: {wigos_id}') params['wigosId'] = wigos_id + elif station_name is not None: + request = f'{self.api_url}/stations/approvedStations/names' + params['q'] = station_name else: if program is not None: LOGGER.debug(f'Program: {program}') @@ -555,9 +560,10 @@ def station(ctx, env, identifier, summary=False, format_='JSON', @cli_options.OPTION_ENV @cli_options.OPTION_VERBOSITY @click.option('--program', '-p', help='Program Affiliation') +@click.option('--station-name', '-sn', help='Station name') @click.option('--station-type', '-st', help='Station type') -def stations(ctx, env, program=None, country=None, station_type=None, - verbosity=None): +def stations(ctx, env, program=None, country=None, station_name=None, + station_type=None, verbosity=None): """get list of OSCAR stations""" if verbosity is not None: @@ -566,7 +572,8 @@ def stations(ctx, env, program=None, country=None, station_type=None, logging.getLogger(__name__).addHandler(logging.NullHandler()) o = OSCARClient(env=env) - matching_stations = o.get_stations(program=program, country=country) + matching_stations = o.get_stations(station_name=station_name, + program=program, country=country) result = json.dumps(matching_stations, indent=4) click.echo(f'Number of stations: {len(matching_stations)}\nStations:\n{result}') # noqa