diff --git a/dispatcher/backend/maint-scripts/report_youtube_api_keys.py b/dispatcher/backend/maint-scripts/report_youtube_api_keys.py index 874c214b..6162e70d 100755 --- a/dispatcher/backend/maint-scripts/report_youtube_api_keys.py +++ b/dispatcher/backend/maint-scripts/report_youtube_api_keys.py @@ -62,7 +62,21 @@ def report_youtube_api_keys(session: so.Session, *, display_unknown_secrets=Fals ), "schedules": [], } - schedules_by_api_key[hashed_api_key]["schedules"].append(schedule.name) + + schedule_data = {"name": schedule.name, "media_count": 0} + + if schedule.most_recent_task_id is not None: + for task in sorted( + schedule.tasks, key=lambda task: task.updated_at, reverse=True + ): + if task.status != "succeeded": + continue + media_count = 0 + for file in task.files.values(): + media_count += file["info"]["media_count"] + schedule_data["media_count"] = media_count + break + schedules_by_api_key[hashed_api_key]["schedules"].append(schedule_data) report_data = {} report_data["nb_schedules"] = len(schedules) @@ -76,7 +90,12 @@ def report_youtube_api_keys(session: so.Session, *, display_unknown_secrets=Fals if hashed_api_key in known_api_keys.keys() else "unknown" ), - "schedules": sorted(data["schedules"]), + "total_media": sum( + [schedule["media_count"] for schedule in data["schedules"]] + ), + "schedules": sorted( + data["schedules"], key=lambda schedule: schedule["name"] + ), } ) if display_unknown_secrets and hashed_api_key not in known_api_keys.keys(): @@ -88,6 +107,7 @@ def report_youtube_api_keys(session: so.Session, *, display_unknown_secrets=Fals report_data["keys"].append( { "name": key_name, + "total_media": 0, "schedules": [], } ) diff --git a/dispatcher/backend/maint-scripts/report_youtube_api_keys.txt b/dispatcher/backend/maint-scripts/report_youtube_api_keys.txt index 43f4fed9..d2fad4e9 100644 --- a/dispatcher/backend/maint-scripts/report_youtube_api_keys.txt +++ b/dispatcher/backend/maint-scripts/report_youtube_api_keys.txt @@ -5,9 +5,9 @@ Please review this report, take appropriate action if needed and close the issue **{{ report_data.nb_schedules }}** recipes using an API key have been found. {% for key in report_data["keys"] %} -{% if key.name != "unknown" %}## {{ key.name }}{% else %}## Unknown Key{% endif %} +{% if key.name != "unknown" %}## {{ key.name }} ({{ key.total_media }} total medias){% else %}## Unknown Key{% endif %} {% for schedule in key["schedules"] %} -- {{ schedule }}{% endfor %} +- {{ schedule.name }} {% if schedule.media_count != 0 %}({{ schedule.media_count }} medias){% else %}(unknown amount of media){% endif %}{% endfor %} {% if key["schedules"] | length == 0 %}*Key is not used*{% endif %} {% endfor %} *This report has been automatically generated at {{report_data.datetime}} UTC* \ No newline at end of file