Created
June 2, 2023 18:53
-
-
Save SpotlightKid/f8d9dee709bb7e4c36e12a2bb530fb30 to your computer and use it in GitHub Desktop.
Examine an RSS feed retrieved from given URL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
"""Examine an RSS feed retrieved from given URL.""" | |
import sys | |
from xml.dom.minidom import parseString as parse_xml | |
import feedparser | |
import requests | |
if len(sys.argv) > 1: | |
url = sys.argv[1] | |
else: | |
url = "https://lmc.nyxkn.org/rss" | |
res = requests.get(url) | |
if res.status_code != 200: | |
sys.exit(f"Could not retrieve {url}.") | |
print("Headers:\n========\n") | |
for name, val in res.headers.items(): | |
print(f"{name}: {val}") | |
feed = feedparser.parse(res.text, response_headers=res.headers) | |
print("\nFeed:\n=====\n") | |
for name, val in feed.feed.items(): | |
print(f"{name}: {val}") | |
print("\nEntries:\n========\n") | |
for i, entry in enumerate(feed.entries): | |
print(f"Entry {i:02}:\n=========\n") | |
for name, val in entry.items(): | |
print(f"{name}: {val}") | |
print() | |
doc = parse_xml(res.text) | |
print("Raw RSS XML:\n============\n") | |
print(doc.toprettyxml()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment