Skip to content

Commit

Permalink
print total image count
Browse files Browse the repository at this point in the history
  • Loading branch information
KatrionaGoldmann committed Nov 6, 2024
1 parent cd83384 commit 531b23d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ credentials.json
.ipynb_checkpoints/
*.out
data/
models/
16 changes: 8 additions & 8 deletions print_deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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"]
Expand Down Expand Up @@ -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")
Expand All @@ -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:
Expand Down

0 comments on commit 531b23d

Please sign in to comment.