58 lines
1.8 KiB
Python
58 lines
1.8 KiB
Python
#!/usr/bin/python
|
|
|
|
from defusedxml.ElementTree import fromstring
|
|
import urllib.request
|
|
import datetime
|
|
import os
|
|
|
|
os.chdir("/srv/http/dukun.de/xox/ZanderZeichen/")
|
|
|
|
# rss-xml URL
|
|
url = "https://www1.wdr.de/mediathek/audio/zeitzeichen/zeitzeichen-podcast-100.podcast"
|
|
|
|
def findZander(today):
|
|
"""
|
|
"""
|
|
# find metadata
|
|
for n, item in enumerate(today):
|
|
if item.tag.find("title") >= 0:
|
|
title = today[n].text
|
|
if item.tag.find("author") >= 0:
|
|
author = today[n].text
|
|
if item.tag.find("enclosure") >= 0:
|
|
podcasturl = today[n].attrib["url"]
|
|
|
|
# check for Zander
|
|
if author.find("Zander") >= 0:
|
|
print(f"ZanderAlert: {title}\nDownload-URL: {podcasturl}")
|
|
return {"url": podcasturl, "title": title, "full_item": today}
|
|
return None
|
|
|
|
# read rss feed
|
|
with urllib.request.urlopen(url) as response:
|
|
assert response.status == 200, f"Webrequest fehlgeschlagen, stimmt die URL noch?"
|
|
feed = fromstring(response.read())[0]
|
|
|
|
# read entries in rss feed until first entry (today)
|
|
for i in feed:
|
|
if i.tag == "item":
|
|
metadata = findZander(i)
|
|
break
|
|
|
|
# download episode download and regenerate zanderzeichen feed
|
|
if metadata is not None:
|
|
day, month, year = datetime.datetime.now().strftime("%d.%m.%Y").split(".")
|
|
title = metadata["title"]
|
|
for i in (",", "(", ")"): # get rid of unwanted characters in title
|
|
title = title.replace(i, "")
|
|
refdate = title.split(" ")[-1].replace(".", "") # generate reference date
|
|
title = " ".join(title.split(" ")[:-1]) # strip reference date
|
|
|
|
# destination file name
|
|
destination = f"files/wdrzeitzeichen_{year}-{month}-{day}_{title}_{refdate}_wdr5.mp3"
|
|
# actual download of file
|
|
urllib.request.urlretrieve(metadata["url"], destination)
|
|
|
|
# regenerate zanderzeichen feed
|
|
import genfeed
|