Skip to content

Commit

Permalink
Merge pull request #11 from wmo-im/tk-updates-2024-04-01
Browse files Browse the repository at this point in the history
remove wis2 subcommand in CLI
  • Loading branch information
tomkralidis authored Apr 5, 2024
2 parents 070a797 + c94ff35 commit 96c50fc
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8, 3.9]
python-version: ["3.8", "3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
Expand Down
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ python3 setup.py install

## Running

The canonical URL for the GDC is https://api.weather.gc.ca/collections/wis2-discovery-metadata.
The canonical URL for the GDC is https://api.weather.gc.ca.

To use a different catalogue, set the `PYWISCAT_GDC_URL` environmnent variable before running pywiscat.

Expand All @@ -47,16 +47,19 @@ pywiscat --version
## WIS2 workflows

# search the WIS2 Global Discovery Catalogue (GDC)
pywiscat wis2 search
pywiscat search

# search the WIS2 Global Discovery Catalogue (GDC) with a full text query
pywiscat wis2 search -q radar
pywiscat search --query radar

# search the WIS2 Global Discovery Catalogue (GDC) for only recommended data
pywiscat search --data-policy recommended

# search the WIS2 Global Discovery Catalogue (GDC) with a bounding box query
pywiscat wis2 search --bbox -142,42.-52,84
pywiscat search --bbox -142,42,-52,84

# get more information about a WIS2 GDC record
pywiscat wis2 get urn:x-wmo:md:can:eccc-msc:c7c9d726-c48a-49e3-98ab-78a1ab87cda8
pywiscat get urn:x-wmo:md:can:eccc-msc:c7c9d726-c48a-49e3-98ab-78a1ab87cda8
```

## Using the API
Expand Down
2 changes: 1 addition & 1 deletion pywiscat.env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
PYWISCAT_GDC_URL=https://api.weather.gc.ca/collections/wis2-discovery-metadata
PYWISCAT_GDC_URL=https://api.weather.gc.ca
7 changes: 4 additions & 3 deletions pywiscat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Authors: Tom Kralidis <tomkralidis@gmail.com>
#
# Copyright (c) 2023 Tom Kralidis
# Copyright (c) 2024 Tom Kralidis
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
Expand All @@ -29,7 +29,7 @@

import click

from pywiscat.wis2 import wis2
from pywiscat.wis2.catalogue import get_gdc_record, search_gdc

__version__ = '0.1.dev0'

Expand All @@ -40,4 +40,5 @@ def cli():
pass


cli.add_command(wis2)
cli.add_command(search_gdc)
cli.add_command(get_gdc_record)
25 changes: 19 additions & 6 deletions pywiscat/wis2/catalogue.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Authors: Tom Kralidis <tomkralidis@gmail.com>
#
# Copyright (c) 2023 Tom Kralidis
# Copyright (c) 2024 Tom Kralidis
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
Expand Down Expand Up @@ -40,8 +40,8 @@
from pywiscat.cli_helpers import cli_option_verbosity
LOGGER = logging.getLogger(__name__)

GDC_URL = os.environ.get(
'PYWISCAT_GDC_URL', 'https://api.weather.gc.ca/collections/wis2-discovery-metadata') # noqa
GDC_URL = os.environ.get('PYWISCAT_GDC_URL', 'https://api.weather.gc.ca')
GDC_URL = f'{GDC_URL}/collections/wis2-discovery-metadata'


def get_country_and_centre(identifier):
Expand Down Expand Up @@ -93,6 +93,7 @@ def search(**kwargs: dict) -> dict:
:param kwargs: `dict` of GDC query parameters:
- q: `str` of full-text search
- data_policy: `str` of data policy
- bbox: `list` of minx, miny, maxx, maxy
- begin: `str` of begin datetime
- end: `str` of end datetime
Expand All @@ -115,6 +116,7 @@ def search(**kwargs: dict) -> dict:

begin = kwargs2.pop('begin', None)
end = kwargs2.pop('end', None)
data_policy = kwargs2.pop('data_policy', None)

# if type is not None:
# params['type'] = type_
Expand All @@ -139,6 +141,10 @@ def search(**kwargs: dict) -> dict:
if sortby2 is not None:
params['sortby'] = sortby2

LOGGER.debug('Detecting data policy')
if data_policy is not None:
params['wmo:dataPolicy'] = data_policy

LOGGER.debug('Detecting all other query parameters')
for key, value in kwargs2.items():
if value is not None:
Expand Down Expand Up @@ -227,11 +233,17 @@ def get(identifier: str) -> tuple:

@click.command('search')
@click.pass_context
@click.option('--bbox', '-b', help='Bounding box filter')
@click.option('--query', '-q', 'q', help='Full text query')
@click.option('--bbox', '-b', help='Bounding box filter')
@click.option('--data-policy', '-dp', 'data_policy',
type=click.Choice(['core', 'recommended']),
help='Data policy')
@click.option('--begin', 'begin', help='Begin time (in RFC3339 format)')
@click.option('--end', 'end', help='End time (in RFC3339 format)')
@click.option('--sortby', '-s', 'sortby', help='Property to sort by')
@cli_option_verbosity
def search_gdc(ctx, type_='dataset', begin=None, end=None, q=None,
bbox=[], sortby=None, verbosity='NOTSET'):
bbox=[], sortby=None, data_policy=None, verbosity='NOTSET'):
"""Search the WIS2 GDC"""

if bbox:
Expand All @@ -245,7 +257,8 @@ def search_gdc(ctx, type_='dataset', begin=None, end=None, q=None,
end=end,
q=q,
bbox=bbox2,
sortby=sortby
sortby=sortby,
data_policy=data_policy
)

click.echo('\nQuerying WIS2 GDC 🗃️ ...\n')
Expand Down

0 comments on commit 96c50fc

Please sign in to comment.