Skip to content

Commit

Permalink
add a command line argument to control whether use cached data
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelchin committed Apr 12, 2024
1 parent 91feca1 commit e60c282
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions gplately/ptt/gpmdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ def add_arguments(parser: argparse.ArgumentParser):
"-m", "--model", type=str, dest="model_name", default="Muller2022"
)
parser.add_argument("-o", "--outfile", type=str, dest="outfile")
parser.add_argument(
"--use-cached-data",
action="store_true",
help="use cached data for debugging purpose",
)


__description__ = """Retrieve paleomagnetic data from https://www.gpmdb.net, create GPlates-compatible VGP features and save the VGP features in a .gpmlz file.
Expand Down Expand Up @@ -145,10 +150,10 @@ def add_arguments(parser: argparse.ArgumentParser):


def main(args):
Path(DATA_CACHE_DIR).mkdir(parents=True, exist_ok=True)

# get query data
if not os.path.isfile(f"{DATA_CACHE_DIR}/{QUERY_DATA_FILENAME}"):
if not args.use_cached_data or not os.path.isfile(
f"{DATA_CACHE_DIR}/{QUERY_DATA_FILENAME}"
):
try:
response = requests.get(QUERY_DATA_URL, verify=False)
query_data = response.json()
Expand All @@ -160,6 +165,7 @@ def main(args):
f"FATAL: The {QUERY_DATA_URL} did not return valid data. Check and make sure the website is up and running!"
)
sys.exit(1)
Path(DATA_CACHE_DIR).mkdir(parents=True, exist_ok=True)
with open(f"{DATA_CACHE_DIR}/{QUERY_DATA_FILENAME}", "w+") as outfile:
outfile.write(json.dumps(query_data))
else:
Expand All @@ -179,7 +185,9 @@ def main(args):
df_query = df_query.sort_values(by=["RESULTNO"], ignore_index=True)

# get pmag-result data
if not os.path.isfile(f"{DATA_CACHE_DIR}/{PMAG_RESULT_FILENAME}"):
if not args.use_cached_data or not os.path.isfile(
f"{DATA_CACHE_DIR}/{PMAG_RESULT_FILENAME}"
):
try:
response = requests.get(PMAG_RESULT_URL, verify=False)
pmagresult_data = response.json()
Expand Down

0 comments on commit e60c282

Please sign in to comment.