From e7b72b17543a0f54171c4b89d9e6f4b3a76c196e Mon Sep 17 00:00:00 2001 From: pierregeeraert Date: Thu, 9 Jul 2026 09:13:36 +0100 Subject: [PATCH] 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()