From 531b23d12acad27dee3cee17ebdba3441bfaa5ba Mon Sep 17 00:00:00 2001 From: KatrionaGoldmann Date: Wed, 6 Nov 2024 16:57:20 +0000 Subject: [PATCH] print total image count --- .gitignore | 1 + print_deployments.py | 16 ++++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 2c5fde6..a769b8a 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ credentials.json .ipynb_checkpoints/ *.out data/ +models/ diff --git a/print_deployments.py b/print_deployments.py index 1c79fe8..903e52d 100644 --- a/print_deployments.py +++ b/print_deployments.py @@ -43,10 +43,7 @@ def count_files(s3_client, bucket_name, prefix): page_iterator = paginator.paginate(**operation_parameters) count=0 for page in page_iterator: - if not os.path.basename(page.get("Contents", [])[0]["Key"]).startswith("$"): - count += page.get("KeyCount", 0) - file_i = page.get("Contents", [])[0]["Key"] - + count += page.get("KeyCount", 0) return count def print_deployments(include_inactive=False, subset_countries=None, print_image_count=True): @@ -55,7 +52,6 @@ def print_deployments(include_inactive=False, subset_countries=None, print_image """ import sys print(sys.version) - # Get all deployments username = aws_credentials["UKCEH_username"] @@ -92,8 +88,7 @@ def print_deployments(include_inactive=False, subset_countries=None, print_image print("\n\033[1m" + country + " (" + country_code + ") has " + str(len(country_depl)) + act_string + "deployments:\033[0m") all_deps = list(set([x['deployment_id'] for x in country_depl])) - - + total_images = 0 for dep in sorted(all_deps): dep_info = [x for x in country_depl if x['deployment_id'] == dep][0] print(f"\033[1m - Deployment ID: {dep_info['deployment_id']}, Name: {dep_info['location_name']}, Deployment Key: '{dep_info['location_name']} - {dep_info['camera_id']}'\033[0m") @@ -102,11 +97,16 @@ def print_deployments(include_inactive=False, subset_countries=None, print_image # get the number of images for this deployment prefix = f"{dep_info['deployment_id']}/snapshot_images" bucket_name = dep_info["country_code"].lower() - + if print_image_count: count = count_files(s3_client, bucket_name, prefix) + total_images = total_images + count print(f" - This deployment has \033[1m{count}\033[0m images.\n") + + if print_image_count: + print(f"\033[1m - {country} has {total_images}\033[0m images total\033[0m\n") + if __name__ == "__main__": with open("./credentials.json", encoding="utf-8") as config_file: