Skip to content

Commit

Permalink
add station search by name
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkralidis committed Oct 8, 2024
1 parent abc8b3a commit 352b06f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 11 additions & 4 deletions pyoscar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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}')
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down

0 comments on commit 352b06f

Please sign in to comment.