diff --git a/src/admin/api.py b/src/admin/api.py index 0db6144..bb54538 100644 --- a/src/admin/api.py +++ b/src/admin/api.py @@ -45,8 +45,8 @@ def authenticate(): @admin.route("/admin/getStatisticsPerMonth", methods=["GET"]) def monthly_statistics(): is_authenticated() - month = request.args.get('month') - year = request.args.get('year') + month = request.args.get("month") + year = request.args.get("year") amount = shared_models.get_games_played_per_month(month, year) return json.dumps(amount), 200 @@ -56,7 +56,7 @@ def monthly_statistics(): def yearly_statistics(): is_authenticated() - year = request.args.get('year') + year = request.args.get("year") amount = shared_models.get_games_played_per_year(year) return json.dumps(amount), 200 @@ -93,7 +93,7 @@ def get_count_per_month(): """ try: is_authenticated() - year = request.args.get('year') + year = request.args.get("year") year = int(year) count_list = shared_models.get_scores_count_per_month(year) @@ -141,7 +141,10 @@ def admin_page(action): "BLOB_image_count": new_blob_image_count, } except Exception as e: - current_app.logger.error("Something in admin/status failed: " + str(e)) + current_app.logger.error( + "Something in admin/status failed: " + str(e) + ) + return json.dumps(e), 500 return json.dumps(data), 200 elif action == "logging": diff --git a/src/storage.py b/src/storage.py index 0326545..2ac0fd5 100644 --- a/src/storage.py +++ b/src/storage.py @@ -91,7 +91,7 @@ def create_container(): raise Exception("Could not create container") -def image_count(): +def image_count_old(): """ Returns number of images in relevant container. """ @@ -100,6 +100,22 @@ def image_count(): return container_client.get_container_properties().metadata["image_count"] +def image_count(): + blob_service_client = BlobServiceClient.from_connection_string( + Keys.get("BLOB_CONNECTION_STRING") + ) + container_client = blob_service_client.get_container_client( + Keys.get("CONTAINER_NAME") + ) + + # Initialize the counter for all files + file_count = 0 + + # Iterate over all the blobs in the container + file_count = sum(1 for _ in container_client.list_blobs()) + return file_count + + def blob_connection(container_name): """ Helper method for connection to blob service.