implement automatic removal of downloaded files after 4 days, streamline download routine
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
#!/usr/bin/bash
|
#!/usr/bin/bash
|
||||||
link=$(curl -s https://www.ndr.de/radiomv/podcast4418.xml | grep enclosure | cut -d'"' -f2)
|
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
|
wget -q -O new.mp3 $link
|
||||||
md5sum=$(md5sum new.mp3 | cut -d" " -f1)
|
md5sum=$(md5sum new.mp3 | cut -d" " -f1)
|
||||||
if [[ $( ls files | grep $md5sum) ]]; then rm new.mp3 ; exit 0 ; fi
|
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/$(date +%Y-%m-%d-%H-%M)-${md5sum}.mp3
|
||||||
mv new.mp3 files/$newname
|
|
||||||
|
|
||||||
python genfeed.py
|
python genfeed.py
|
||||||
|
|||||||
15
genfeed.py
15
genfeed.py
@@ -4,7 +4,7 @@ import rfeed
|
|||||||
import datetime
|
import datetime
|
||||||
import os
|
import os
|
||||||
|
|
||||||
MAXFILEAGE_IN_DAYS = 14
|
MAXFILEAGE_IN_DAYS = 4
|
||||||
|
|
||||||
|
|
||||||
items = []
|
items = []
|
||||||
@@ -18,15 +18,10 @@ for file in os.listdir("files"):
|
|||||||
hour = int(hour)
|
hour = int(hour)
|
||||||
minute = int(minute)
|
minute = int(minute)
|
||||||
|
|
||||||
# remove old file
|
# remove old files
|
||||||
# if datetime.datetime(year, month, day, hour, minute) \
|
if datetime.datetime.now() - datetime.datetime(year, month, day, hour, minute) > datetime.timedelta(MAXFILEAGE_IN_DAYS):
|
||||||
# + datetime.timedelta(MAXFILEAGE_IN_DAYS) < datetime.datetime.now():
|
os.remove(f"files/{file}")
|
||||||
# print(f"{file} identified as old - DELETING")
|
continue
|
||||||
# print(datetime.datetime(year, month, day, hour, minute))
|
|
||||||
# print(datetime.timedelta(MAXFILEAGE_IN_DAYS))
|
|
||||||
# print(datetime.datetime.now())
|
|
||||||
# #os.remove(f"file/{file}")
|
|
||||||
# continue
|
|
||||||
|
|
||||||
items.append(rfeed.Item(
|
items.append(rfeed.Item(
|
||||||
title=f"Regionalnachrichten {day:0>2d}.{month:0>2d}.{year} {hour:0>2d}:{minute:0>2d}",
|
title=f"Regionalnachrichten {day:0>2d}.{month:0>2d}.{year} {hour:0>2d}:{minute:0>2d}",
|
||||||
|
|||||||
Reference in New Issue
Block a user