Skip to content

Commit

Permalink
Enhance youtube API key reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
benoit74 committed Nov 1, 2024
1 parent b427508 commit 34c42e6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
24 changes: 22 additions & 2 deletions dispatcher/backend/maint-scripts/report_youtube_api_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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():
Expand All @@ -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": [],
}
)
Expand Down
4 changes: 2 additions & 2 deletions dispatcher/backend/maint-scripts/report_youtube_api_keys.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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*

0 comments on commit 34c42e6

Please sign in to comment.