Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
Expand Down
11 changes: 10 additions & 1 deletion src/gdex_api_client/gdex_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import argparse
import codecs
import pdb
import re


BASE_URL = 'https://gdex.ucar.edu/api/'
Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -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)
Expand Down
Loading