implement automatic removal of downloaded files after 4 days, streamline download routine

This commit is contained in:
fordprefect
2021-12-01 16:42:26 +01:00
parent 1290e10115
commit aa7fc9906e
2 changed files with 8 additions and 12 deletions

View File

@@ -1,9 +1,10 @@
#!/usr/bin/bash
link=$(curl -s https://www.ndr.de/radiomv/podcast4418.xml | grep enclosure | cut -d'"' -f2)
# break if download link is empty
[[ $link ]] || exit 0
wget -q -O new.mp3 $link
md5sum=$(md5sum new.mp3 | cut -d" " -f1)
if [[ $( ls files | grep $md5sum) ]]; then rm new.mp3 ; exit 0 ; fi
newname=$(date +%Y-%m-%d-%H-%M)-${md5sum}.mp3
mv new.mp3 files/$newname
mv new.mp3 files/$(date +%Y-%m-%d-%H-%M)-${md5sum}.mp3
python genfeed.py

View File

@@ -4,7 +4,7 @@ import rfeed
import datetime
import os
MAXFILEAGE_IN_DAYS = 14
MAXFILEAGE_IN_DAYS = 4
items = []
@@ -18,15 +18,10 @@ for file in os.listdir("files"):
hour = int(hour)
minute = int(minute)
# remove old file
# if datetime.datetime(year, month, day, hour, minute) \
# + datetime.timedelta(MAXFILEAGE_IN_DAYS) < datetime.datetime.now():
# print(f"{file} identified as old - DELETING")
# print(datetime.datetime(year, month, day, hour, minute))
# print(datetime.timedelta(MAXFILEAGE_IN_DAYS))
# print(datetime.datetime.now())
# #os.remove(f"file/{file}")
# continue
# remove old files
if datetime.datetime.now() - datetime.datetime(year, month, day, hour, minute) > datetime.timedelta(MAXFILEAGE_IN_DAYS):
os.remove(f"files/{file}")
continue
items.append(rfeed.Item(
title=f"Regionalnachrichten {day:0>2d}.{month:0>2d}.{year} {hour:0>2d}:{minute:0>2d}",