aboutsummaryrefslogtreecommitdiffstats
path: root/playlist_generator/generate_daily.py
diff options
context:
space:
mode:
authorPinapelz <yukais@pinapelz.com>2026-06-07 02:39:17 -0700
committerPinapelz <yukais@pinapelz.com>2026-06-07 02:39:17 -0700
commit38f01714c551f3d97406703904f9782d42012fe9 (patch)
tree98b58e13fa1a61a3ad4165a73133aed2f8799f3d /playlist_generator/generate_daily.py
parent9e1370fb75cbe80edcd3e2c552a9f60ef2f2cc4c (diff)
add support for ntfy in daily generation script
Diffstat (limited to 'playlist_generator/generate_daily.py')
-rw-r--r--playlist_generator/generate_daily.py28
1 files changed, 24 insertions, 4 deletions
diff --git a/playlist_generator/generate_daily.py b/playlist_generator/generate_daily.py
index b810ba9..0a7c992 100644
--- a/playlist_generator/generate_daily.py
+++ b/playlist_generator/generate_daily.py
@@ -19,7 +19,17 @@ HEARDLE_SALT = (
os.getenv("VITE_HEARDLE_SALT")
or os.getenv("OBFUSCATION_KEY")
)
+NTFY_URL = os.getenv("NTFY_URL")
+NTFY_TOKEN = os.getenv("NTFY_TOKEN")
+def send_notification(message: str):
+ if not NTFY_URL or not NTFY_TOKEN:
+ return
+ requests.post(
+ NTFY_URL,
+ data=message.encode(encoding='utf-8'),
+ headers={"Authorization": f"Bearer {NTFY_TOKEN}"},
+ )
def xor_buffer(data: bytes, key: bytes) -> bytes:
return bytes(b ^ key[i % len(key)] for i, b in enumerate(data))
@@ -130,13 +140,23 @@ def main():
new_data = True
daily_data = fetch_daily()
data = decode_data(daily_data["data"], daily_data["date"])
- print(data)
youtube_id = data["youtubeId"]
- clip_path = download_random_segment_mp3(youtube_id)
+ try:
+ clip_path = download_random_segment_mp3(youtube_id)
+ except:
+ print(f"Failed to download clip for {youtube_id}")
+ send_notification(f"K-HEARDLE: Failed to download clip for {youtube_id}")
+ return
date = daily_data["date"]
- upload_to_r2(clip_path, f"kheardle/{date}.mp3")
- delete_file(clip_path)
+ try:
+ upload_to_r2(clip_path, f"kheardle/{date}.mp3")
+ delete_file(clip_path)
+ except:
+ print(f"Failed to upload clip for {date}")
+ send_notification(f"K-HEARDLE: Failed to upload clip for {date}")
+ return
write_json("save.json", daily_data)
+ send_notification(f"K-HEARDLE: Successfully generated daily playlist for {date}")
if __name__ == "__main__":
main()
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage