From 459c53f79d9006ee5f72b43a9ab3330ddf6d64bc Mon Sep 17 00:00:00 2001 From: Tom Kralidis Date: Tue, 13 Aug 2024 07:15:13 -0400 Subject: [PATCH] require station metadata file explicitly --- .github/workflows/tests-docker.yml | 2 +- .../wis2box/metadata/station.py | 28 ++++++------------- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/.github/workflows/tests-docker.yml b/.github/workflows/tests-docker.yml index 08f9e4e2..0e2388af 100644 --- a/.github/workflows/tests-docker.yml +++ b/.github/workflows/tests-docker.yml @@ -55,7 +55,7 @@ jobs: curl -X POST http://localhost/wis2downloader/subscriptions -H "Content-Type: application/json" -H "Authorization: Bearer github123" -d @test.json - name: populate stations from CSV 📡 run: | - python3 wis2box-ctl.py execute wis2box metadata station publish-collection + python3 wis2box-ctl.py execute wis2box metadata station publish-collection --path /data/wis2box/metadata/station/station_list.csv - name: add Malawi synop data (csv2bufr synop_bufr template) 🇲🇼 env: TOPIC_HIERARCHY: mw-mw_met_centre.data.core.weather.surface-based-observations.synop diff --git a/wis2box-management/wis2box/metadata/station.py b/wis2box-management/wis2box/metadata/station.py index 68590510..7c9ee420 100644 --- a/wis2box-management/wis2box/metadata/station.py +++ b/wis2box-management/wis2box/metadata/station.py @@ -39,7 +39,7 @@ from wis2box.api import ( delete_collection_item, setup_collection, upsert_collection_item ) -from wis2box.env import (DATADIR, API_BACKEND_URL, DOCKER_API_URL, +from wis2box.env import (API_BACKEND_URL, DOCKER_API_URL, BROKER_HOST, BROKER_USERNAME, BROKER_PASSWORD, BROKER_PORT) from wis2box.metadata.base import BaseMetadata @@ -49,8 +49,6 @@ LOGGER = logging.getLogger(__name__) -STATION_METADATA = DATADIR / 'metadata' / 'station' -STATIONS = STATION_METADATA / 'station_list.csv' WMDR_CODELISTS = Path('/home/wis2box/wmdr-codelists') @@ -294,7 +292,7 @@ def add_topic_hierarchy(new_topic: str, territory_name: str = None, upsert_collection_item('stations', feature) -def publish_from_csv(path: Path = None, topic: str = None) -> None: +def publish_from_csv(path: Path, topic: str = None) -> None: """ Publishes station collection to API config and backend from csv @@ -304,26 +302,16 @@ def publish_from_csv(path: Path = None, topic: str = None) -> None: :returns: `None` """ - stations_csv_to_publish = STATIONS - - if path is not None: - if not path.exists(): - msg = f'Station file {path} does not exist' - LOGGER.error(msg) - raise RuntimeError(msg) - - stations_csv_to_publish = path - else: - if not STATIONS.exists(): - msg = f'Please create a station metadata file in {STATION_METADATA}' # noqa - LOGGER.error(msg) - raise RuntimeError(msg) + if not path.exists(): + msg = f'Station file {path} does not exist' + LOGGER.error(msg) + raise RuntimeError(msg) oscar_baseurl = 'https://oscar.wmo.int/surface/#/search/station/stationReportDetails' # noqa - LOGGER.debug(f'Publishing station list from {stations_csv_to_publish}') + LOGGER.debug(f'Publishing station list from {path}') station_list = [] - with stations_csv_to_publish.open() as fh: + with path.open() as fh: reader = csv.DictReader(fh) for row in reader: