Skip to content

Instantly share code, notes, and snippets.

@vwillcox
Created April 18, 2022 14:39
Show Gist options
  • Save vwillcox/d505348422abb8564d34ca159baaca05 to your computer and use it in GitHub Desktop.
Save vwillcox/d505348422abb8564d34ca159baaca05 to your computer and use it in GitHub Desktop.
Show RSS feed from RPILocator RSS - simple display
from bs4 import BeautifulSoup
import requests
import re
headers = {
'User-Agent': 'your-user-agent-here'
}
class ReadRss:
def __init__(self, rss_url, headers):
self.url = rss_url
self.headers = headers
cats = []
try:
self.r = requests.get(rss_url, headers=self.headers)
self.status_code = self.r.status_code
except Exception as e:
print('Error fetching the URL: ', rss_url)
print(e)
try:
self.soup = BeautifulSoup(self.r.text, 'xml')
except Exception as e:
print('Could not parse the xml: ', self.url)
print(e)
self.articles = self.soup.findAll('item')
print('This was last updated: ' + self.soup.lastBuildDate.text)
for getfeed in self.articles:
print(getfeed.title.text + '. Checked at: ' + getfeed.pubDate.text)
if __name__ == '__main__':
feed = ReadRss('https://rpilocator.com/feed/?country=uk&cat=Pi4&instock', headers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment