Skip to content

Commit

Permalink
fix Python API refs
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkralidis committed Sep 19, 2023
1 parent 62c2767 commit c8d5b63
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 28 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ jobs:
name: Setup Python ${{ matrix.python-version }}
with:
python-version: ${{ matrix.python-version }}
- name: Install system dependencies 📦
run: sudo apt-get install -y libxml2-dev
- name: Install requirements 📦
run: |
python3 -m pip install --upgrade pip
Expand All @@ -27,6 +25,6 @@ jobs:
run: python3 setup.py test
- name: run flake8 ⚙️
run: |
find . -type f -name "*.py" | xargs flake8 --ignore=E501,E402
find . -type f -name "*.py" | xargs flake8
- name: build Python package 🏗️
run: python3 setup.py sdist bdist_wheel --universal
6 changes: 3 additions & 3 deletions pywiscat/wis2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

import click

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


@click.group()
Expand All @@ -38,5 +38,5 @@ def wis2():
pass


wis2.add_command(search)
wis2.add_command(get)
wis2.add_command(search_gdc)
wis2.add_command(get_gdc_record)
39 changes: 19 additions & 20 deletions pywiscat/wis2/catalogue.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def get_country_prettified(country):
return flag.flagize(f'{iso3166.name} :{iso3166.alpha2}:')


def search_gdc(**kwargs: dict) -> dict:
def search(**kwargs: dict) -> dict:
"""
Search the GDC
Expand All @@ -108,13 +108,13 @@ def search_gdc(**kwargs: dict) -> dict:

kwargs2 = kwargs

sortby = kwargs2.pop('sortby')
_ = kwargs2.pop('type_')
sortby = kwargs2.pop('sortby', None)
_ = kwargs2.pop('type_', None)
datetime_ = None
sortby2 = None

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

# if type is not None:
# params['type'] = type_
Expand Down Expand Up @@ -156,7 +156,7 @@ def search_gdc(**kwargs: dict) -> dict:
LOGGER.debug(f'URL: {response.url}')

if not response.ok:
LOGGER.warning(f'ERROR: {response.text}')
LOGGER.debug(f'ERROR: {response.text}')
return

response_json = response.json()
Expand Down Expand Up @@ -205,7 +205,7 @@ def search_gdc(**kwargs: dict) -> dict:
return output


def get_gdc_record(identifier: str) -> tuple:
def get(identifier: str) -> tuple:
"""
Get GDC record by identifier
Expand All @@ -220,19 +220,18 @@ def get_gdc_record(identifier: str) -> tuple:
LOGGER.debug(f'URL: {response.url}')

if not response.ok:
LOGGER.warning(f'ERROR: {response.text}')
return
LOGGER.debug(f'ERROR: {response.text}')

return response.url, response.json()


@click.command()
@click.command('search')
@click.pass_context
@cli_option_verbosity
@click.option('--bbox', '-b', help='Bounding box filter')
@click.option('--query', '-q', 'q', help='Full text query')
def search(ctx, type_='dataset', begin=None, end=None, q=None,
bbox=[], sortby=None, verbosity='NOTSET'):
@cli_option_verbosity
def search_gdc(ctx, type_='dataset', begin=None, end=None, q=None,
bbox=[], sortby=None, verbosity='NOTSET'):
"""Search the WIS2 GDC"""

if bbox:
Expand All @@ -250,7 +249,7 @@ def search(ctx, type_='dataset', begin=None, end=None, q=None,
)

click.echo('\nQuerying WIS2 GDC 🗃️ ...\n')
results = search_gdc(**params)
results = search(**params)

if results is None:
raise click.ClickException('Could not query catalogue')
Expand All @@ -272,21 +271,21 @@ def search(ctx, type_='dataset', begin=None, end=None, q=None,
click.echo(pt.get_string())


@click.command()
@click.command('get')
@click.pass_context
@cli_option_verbosity
@click.argument('identifier')
def get(ctx, identifier, verbosity):
@cli_option_verbosity
def get_gdc_record(ctx, identifier, verbosity):
"""Get a WIS2 GDC record by identifier"""

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

skip_rels = ['root', 'self', 'alternate', 'collection']

url, result = get_gdc_record(identifier)
url, result = get(identifier)

if result is None:
raise click.ClickException('Record identifier not found')
if 'description' in result:
raise click.ClickException(f'Record identifier {identifier} not found')

country, centre_id = get_country_and_centre(result['id'])
country = get_country_prettified(country)
Expand Down
2 changes: 0 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
click
emoji-country-flag
iso3166
lxml
prettytable
pywcmp
requests

0 comments on commit c8d5b63

Please sign in to comment.