diff --git a/zanderdetect.py b/zanderdetect.py index ee80e7d..7230fc1 100644 --- a/zanderdetect.py +++ b/zanderdetect.py @@ -2,6 +2,7 @@ from defusedxml.ElementTree import fromstring import urllib.request +import datetime url = "https://www1.wdr.de/mediathek/audio/zeitzeichen/zeitzeichen-podcast-100.podcast" @@ -14,13 +15,31 @@ def findZander(today): if item.tag.find("enclosure") >= 0: podcasturl = today[n].attrib["url"] - if author.find("Zander") > 0: + if author.find("Zander") >= 0: print(f"ZanderAlert: {title}\nDownload-URL: {podcasturl}") + return {"url": podcasturl, "title": title, "full_item": today} + return None with urllib.request.urlopen(url) as response: feed = fromstring(response.read())[0] for i in feed: if i.tag == "item": - findZander(i) + metadata = findZander(i) break + +# future feature: episode download and feed regeneration + +if metadata is not None: + # wdrzeitzeichen_2017-05-16_Voltaire wird verhaftet_16051717_wdr5.mp3 + day, month, year = datetime.datetime.now().strftime("%d.%m.%Y").split(".") + title = metadata["title"] + for i in (",", "(", ")"): + title = title.replace(i, "") + refdate = title.split(" ")[-1].replace(".", "") + title = " ".join(title.split(" ")[:-1]) + + destination = f"files/wdrzeitzeichen_{year}-{month}-{day}_{title}_{refdate}_wdr5.mp3" + urllib.request.urlretrieve(metadata["url"], "test/"+destination) + + import genfeed