From e7b72b17543a0f54171c4b89d9e6f4b3a76c196e Mon Sep 17 00:00:00 2001 From: pierregeeraert Date: Thu, 9 Jul 2026 09:13:36 +0100 Subject: [PATCH 1/3] use temporary folder to avoid downloading into disk --- django_code/apps/podcast_aggregator/utils.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/django_code/apps/podcast_aggregator/utils.py b/django_code/apps/podcast_aggregator/utils.py index 26c41de..1466af0 100644 --- a/django_code/apps/podcast_aggregator/utils.py +++ b/django_code/apps/podcast_aggregator/utils.py @@ -3,6 +3,8 @@ import xmltodict from urllib import request as urlrequest from apps.telegram_communication.utils import telegramUtils from .models import podcastData +import tempfile +import time proxy_url = 'http://gluetun-svc.gluetun.svc:8888' @@ -47,7 +49,9 @@ def download_news_mp3(url_mp3, filename): print("Downloading : " + filename +" -- " + url_mp3) try: + urlrequest.urlretrieve(url_mp3, filename) + except: print("Can't download " + filename +" -- " + url_mp3 + " == Cancelling") return 0 @@ -71,8 +75,13 @@ def podcasts(): today_podcast = rss_to_dict(url) print(today_podcast) - file= pretty_filename(today_podcast[1],'mp3') - download_news_mp3(today_podcast[2],file) - telegram.send_document(file,str(today_podcast[0])+" "+str(today_podcast[1])) + pretty_file_name = pretty_filename(today_podcast[1],'mp3') + + temp = tempfile.TemporaryDirectory() + temp_path = temp.name.replace("\\", "/") + file_path = temp_path+"/"+pretty_file_name + download_news_mp3(today_podcast[2],file_path) + print(file_path) + telegram.send_document(file_path,str(today_podcast[0])+" "+str(today_podcast[1])) #main() From a3fb4d843a17d3ee5139df3f8dafc416ab64ee93 Mon Sep 17 00:00:00 2001 From: pierregeeraert Date: Thu, 9 Jul 2026 09:14:23 +0100 Subject: [PATCH 2/3] remove unnecessary imports --- django_code/apps/podcast_aggregator/utils.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/django_code/apps/podcast_aggregator/utils.py b/django_code/apps/podcast_aggregator/utils.py index 1466af0..b6bb151 100644 --- a/django_code/apps/podcast_aggregator/utils.py +++ b/django_code/apps/podcast_aggregator/utils.py @@ -1,10 +1,12 @@ import requests import xmltodict from urllib import request as urlrequest +import tempfile +#Django import from apps.telegram_communication.utils import telegramUtils from .models import podcastData -import tempfile -import time + + proxy_url = 'http://gluetun-svc.gluetun.svc:8888' From 6f1c8cd8ff504123b63451f683f7279c0e5700e4 Mon Sep 17 00:00:00 2001 From: pierregeeraert Date: Fri, 10 Jul 2026 12:09:31 +0100 Subject: [PATCH 3/3] we can delete the message from telegram from the webui now --- .../apps/telegram_communication/admin.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/django_code/apps/telegram_communication/admin.py b/django_code/apps/telegram_communication/admin.py index 208c31d..be65569 100644 --- a/django_code/apps/telegram_communication/admin.py +++ b/django_code/apps/telegram_communication/admin.py @@ -1,8 +1,26 @@ from django.contrib import admin from import_export.admin import ImportExportModelAdmin from .models import TelegramData +from .utils import telegramUtils + +@admin.action(description="Clear all expired messages") +def messages_cleaning(modeladmin, request, queryset): + telegram = telegramUtils() + telegram.clear_expired_messages() # Register your models here. @admin.register(TelegramData) class JobAdmin(ImportExportModelAdmin): list_display = ('message_id','chat_id','description','creation_date','expiration_date') + actions = [messages_cleaning] + + def delete_queryset(self, request, queryset): + """Given a queryset, delete it from the database.""" + print("here") + telegram = telegramUtils() + list_of_message_id = list(queryset.all().values_list('message_id',flat=True)) + telegram.delete_message(list_of_message_id) + #no queryset.delete() because it is specified in delete_message function already + + +