Skip to content

Commit

Permalink
require station metadata file explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkralidis committed Aug 13, 2024
1 parent fe9a83a commit 459c53f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 8 additions & 20 deletions wis2box-management/wis2box/metadata/station.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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')


Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit 459c53f

Please sign in to comment.