diff options
author | André Glüpker <git@wgmd.de> | 2021-07-29 10:48:55 +0200 |
---|---|---|
committer | André Glüpker <git@wgmd.de> | 2021-07-29 10:51:55 +0200 |
commit | b526cc68929250a7f71ff21ed8410ffd8db87a9d (patch) | |
tree | 54ff4b25b4eea9a142a46741eaf502116b030383 /zdf.py | |
parent | af15eade0f59c17c4867baffe0e1dc05033b06c8 (diff) | |
download | rss-feeds-b526cc68929250a7f71ff21ed8410ffd8db87a9d.tar.gz rss-feeds-b526cc68929250a7f71ff21ed8410ffd8db87a9d.tar.bz2 rss-feeds-b526cc68929250a7f71ff21ed8410ffd8db87a9d.zip |
Format using black
Diffstat (limited to 'zdf.py')
-rwxr-xr-x | zdf.py | 43 |
1 files changed, 24 insertions, 19 deletions
@@ -4,46 +4,48 @@ from datetime import datetime from xml.dom.minidom import parse, parseString import locale + def getText(dom, element): textNode = dom.getElementsByTagName(element)[0].firstChild if textNode: return textNode.data return "" + def zdf(feed): url = f"https://www.zdf.de/rss/zdf/{feed}" try: res = urlopen(Request(url)) except Exception as exc: - logging.error('Request to zdf failed.', exc_info=exc) + logging.error("Request to zdf failed.", exc_info=exc) return None try: rss = res.read() xml = parseString(rss) except Exception as exc: - logging.error('Parsing to zdf failed.', exc_info=exc) + logging.error("Parsing to zdf failed.", exc_info=exc) return None try: - title = getText(xml, 'title') - description = getText(xml, 'description') + title = getText(xml, "title") + description = getText(xml, "description") content = [] - for show in xml.getElementsByTagName('item'): - s_url = getText(show, 'link') + for show in xml.getElementsByTagName("item"): + s_url = getText(show, "link") if not s_url: continue # Full episodes have the ID 100 - if not s_url.endswith('-100.html'): + if not s_url.endswith("-100.html"): continue - s_title = getText(show, 'title') + s_title = getText(show, "title") if not s_title.startswith(title): continue - s_date = getText(show, 'pubDate') + s_date = getText(show, "pubDate") s_date_parsed = datetime.strptime(s_date, "%a, %d %b %Y %H:%M:%S %z") if s_date_parsed.timestamp() > datetime.now().timestamp(): @@ -57,16 +59,18 @@ def zdf(feed): # tmp = datetime.strptime(s_tmp, "%d. %B %Y") # locale.setlocale(locale.LC_TIME, saved) - s_desc = getText(show, 'description') - s_guid = getText(show, 'guid') + s_desc = getText(show, "description") + s_guid = getText(show, "guid") print("Adding", s_url, s_desc) - content.append({ - 'title': s_title, - 'url': s_url, - 'content': s_desc, - 'date': s_date, - 'guid': s_guid, - }) + content.append( + { + "title": s_title, + "url": s_url, + "content": s_desc, + "date": s_date, + "guid": s_guid, + } + ) return { "title": title, @@ -75,7 +79,7 @@ def zdf(feed): "content": content, } except Exception as exc: - logging.error('Working with zdf failed.', exc_info=exc) + logging.error("Working with zdf failed.", exc_info=exc) return None @@ -84,6 +88,7 @@ def main(): # print(zdf("comedy/die-anstalt")) print(zdf("comedy/zdf-magazin-royale")) + if __name__ == "__main__": # if len(sys.argv) != 2: # print('Usage:', sys.argv[0], '<foobar>') |