#!/usr/bin/python from defusedxml.ElementTree import fromstring import urllib.request import datetime url = "https://www1.wdr.de/mediathek/audio/zeitzeichen/zeitzeichen-podcast-100.podcast" def findZander(today): 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"] 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": 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