Skip to content

Instantly share code, notes, and snippets.

@SpotlightKid
Created June 2, 2023 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SpotlightKid/f8d9dee709bb7e4c36e12a2bb530fb30 to your computer and use it in GitHub Desktop.
Save SpotlightKid/f8d9dee709bb7e4c36e12a2bb530fb30 to your computer and use it in GitHub Desktop.
Examine an RSS feed retrieved from given URL
#!/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