diff --git a/pyproject.toml b/pyproject.toml index a997d62..4780a63 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ requires = ["setuptools"] build-backend = "setuptools.build_meta" [project] name = "gdex-api-client" -version = "2.0.2" +version = "2.0.3" dependencies = [ "requests", ] diff --git a/src/gdex_api_client/gdex_client.py b/src/gdex_api_client/gdex_client.py index 8dd7389..dcd9259 100755 --- a/src/gdex_api_client/gdex_client.py +++ b/src/gdex_api_client/gdex_client.py @@ -26,6 +26,7 @@ import argparse import codecs import pdb +import re BASE_URL = 'https://gdex.ucar.edu/api/' @@ -67,6 +68,13 @@ def query(args=None): print(json.dumps(result, indent=3)) return result +def validate_dsid(dsid): + """ Validate dsid from command line input """ + ms = re.match(r'^([a-z]{1})(\d{3})(\d{3})$', dsid) + if ms: + return dsid + else: + raise ValueError("dataset number 'dsid' must be formatted as 'dnnnnnn'") def get_userinfo(): """Get token from command line.""" @@ -500,10 +508,11 @@ def write_control_file_template(ds, write_location='./'): Returns: dict: JSON decoded result of the query. """ + dsid = validate_dsid(ds) _json = get_control_file_template(ds) control_str = _json['data']['template'] - template_filename = write_location + ds + '_control.ctl' + template_filename = write_location + dsid + '_control.ctl' if os.path.exists(template_filename): print(template_filename + " already exists.\nExiting") exit(1)