RSS Feed reader - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: RSS Feed reader (/thread-11980.html) |
RSS Feed reader - rfrancocantero - Aug-03-2018 Hi, I'm still new to Python and I'm playing around with an RSS reader. The code actually works so far so I'm very proud of myself The code below reads ONE rss feed and matches it against keywords and based on that it perfoms an action. The only thing is, it only reads ONE rss feed and I would like to let it read more than ONE feed. So I thought that I could change: d = feedparser.parse('https://feed1.rss')into: d = feedparser.parse('https://feed1.rss','https://feed2.rss')But that doesn't seem to work. What would be the easiest way to achieve this? Original and full code: #!/usr/bin/python import feedparser import os import time # Reset old_message old_message = "" # Reset flag flag = 0 while True: # Whipe screen os.system('clear') # Read RSS Feed d = feedparser.parse('https://feed1.rss') # Gather title title = d['entries'][0]['title'] # Title to uppercase title = title.upper() # Gather description description = d['entries'][0]['description'] # Description to uppercase description = description.upper() # Combine title and description to message message = title + " " + description # Conditions need to be in capitals if message.find("56") != -1: flag = 1 if message.find("HO") != -1: flag = 1 # If flag = true if flag == 1: if message != old_message: print("\033[1;31;40m *** ALERT ***") old_message = message print title print description print flag flag = 0 print("\033[1;32;40m") time.sleep(10) RE: RSS Feed reader - Vysero - Aug-03-2018 I am not positive but you could try something like: a = feedparser.parse('https://feed1.rss') b = feedparser.parse('https://feed2.rss') c = feedparser.parse('https://feed3.rss') title_a = a['entries'][0]['title'] title_b = b['entries'][0]['title'] title_c = c['entries'][0]['title']Otherwise, you might look into something called threading. RE: RSS Feed reader - rfrancocantero - Aug-03-2018 (Aug-03-2018, 03:52 PM)Vysero Wrote: I am not positive but you could try something like: I don't think this will work since you're splitting the entries per feed. I want to combine the feeds in one variable (d) RE: RSS Feed reader - Vysero - Aug-03-2018 That's okay I am complexly inexperienced with the feedparser class. You might try something like this: RSS_URLS = [ 'https://feed1.rss', 'https://feed2.rss', ] feeds = [] for url in RSS_URLS: feeds.append(feedparser.parse(url)) for feed in feeds: for post in feed.entries: print(post.title) #or whatever logic you need to use RE: RSS Feed reader - rfrancocantero - Aug-03-2018 (Aug-03-2018, 07:23 PM)Vysero Wrote: That's okay I am complexly inexperienced with the feedparser class. You might try something like this: This prints all RSS items, I just want the last one. For post in feed.entries = 1 to 1 ? |