From b7ca534211f2bc740bb4dd9bbfcfdfc6c9bf7ff6 Mon Sep 17 00:00:00 2001 From: Nick Heppler Date: Thu, 22 May 2025 10:27:36 -0400 Subject: [PATCH] feat: Add --test flag to fetch only the first page of results - Introduced a new command-line argument `--test` to limit data fetching to the first page. - Updated `parse_arguments` function to include the `--test` flag. - Modified the pagination logic in the `main` function to break after the first page when `--test` is enabled. - Enhanced documentation to reflect the new functionality and usage examples. --- app.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index 04bd288..5b5dfe5 100644 --- a/app.py +++ b/app.py @@ -146,10 +146,13 @@ def parse_arguments(): # Add arguments for results per page parser.add_argument('--results_per_page', type=int, default=100, help="Number of results per page (default: 100)") + # Add a test flag + parser.add_argument('--test', action='store_true', help="If set, only fetch the first page of results.") + # Parse the arguments args = parser.parse_args() - return args.results_per_page + return args.results_per_page, args.test def generate_token(username, password, url="https://www.arcgis.com/sharing/rest/generateToken"): """Generates an authentication token.""" @@ -305,8 +308,8 @@ def main(): purge_old_files(purge_days) # Parse command-line arguments - results_per_page = parse_arguments() - logger.info(f"Parsed arguments: results_per_page={results_per_page}") + results_per_page, test_mode = parse_arguments() + logger.info(f"Parsed arguments: results_per_page={results_per_page}, test_mode={test_mode}") # Load environment variables logger.info("Loading environment variables.") @@ -356,6 +359,11 @@ def main(): logger.info("No more data to fetch, stopping pagination.") break + # Break the loop if in test mode + if test_mode: + logger.info("Test mode is enabled, stopping after the first page.") + break + page_number += 1 except Exception as e: logger.error(f"Error fetching or saving data for page {page_number}: {e}", exc_info=True)