From b7ca534211f2bc740bb4dd9bbfcfdfc6c9bf7ff6 Mon Sep 17 00:00:00 2001 From: Nick Heppler Date: Thu, 22 May 2025 10:27:36 -0400 Subject: [PATCH 1/2] 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) From 5be8659264297759411d36cbee59865715a1885e Mon Sep 17 00:00:00 2001 From: Nick Heppler Date: Thu, 22 May 2025 10:32:35 -0400 Subject: [PATCH 2/2] docs: Update README to include --test flag functionality - Added documentation for the new `--test` command-line argument. - Updated the "Script Usage" section to reflect the new flag. - Enhanced the "Functionality" section to mention the test mode feature. - Included examples of how to use the `--test` flag in the "Usage Examples" section. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index afc30ec..90cf852 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,7 @@ python 753DataSync.py --results_per_page 100 | Argument | Description | |----------------------|---------------------------------------------| | `--results_per_page` | Optional. Number of results per API call (default: `100`) | +| `--test` | Optional. If set, only fetch the first page of results. | --- @@ -99,6 +100,7 @@ python 753DataSync.py --results_per_page 100 5. **๐Ÿ“ค Add Features** โ€” Sends data to ArcGIS feature layer. 6. **๐Ÿงน File Cleanup** โ€” Deletes `.json`/`.log` files older than `PURGE_DAYS`. 7. **๐Ÿ“‘ Dynamic Logs** โ€” Logs saved to `753DataSync_YYYY-MM-DD.log`. +8. **๐Ÿงช Test Mode** โ€” Use the `--test` flag to fetch only the first page of results for testing purposes. ---