From e60c2828e1104f22a218053128c03e067b3ccf31 Mon Sep 17 00:00:00 2001 From: michaelchin Date: Fri, 12 Apr 2024 20:42:28 +1000 Subject: [PATCH] add a command line argument to control whether use cached data --- gplately/ptt/gpmdb.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/gplately/ptt/gpmdb.py b/gplately/ptt/gpmdb.py index 1d06771c..140a52fd 100644 --- a/gplately/ptt/gpmdb.py +++ b/gplately/ptt/gpmdb.py @@ -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. @@ -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() @@ -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: @@ -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()