From ff605756ffd50d51b35ace2ae2664f515476e87f Mon Sep 17 00:00:00 2001 From: nemunaire Date: Thu, 1 Oct 2015 00:27:45 +0200 Subject: [PATCH] [news] Add support for RSS feeds and catch ExpatError when trying to parse a bad URL --- modules/news.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/modules/news.py b/modules/news.py index 862ae85..2b4d68e 100644 --- a/modules/news.py +++ b/modules/news.py @@ -26,12 +26,16 @@ def help_full(): def find_rss_links(url): soup = BeautifulSoup(web.getURLContent(url)) - for rss in soup.find_all('link', attrs={"type": re.compile("^application/atom")}): + for rss in soup.find_all('link', attrs={"type": re.compile("^application/(atom|rss)")}): yield urljoin(url, rss["href"]) def get_last_news(url): - feed = Feed(web.getURLContent(url)) - return feed.entries + from xml.parsers.expat import ExpatError + try: + feed = Feed(web.getURLContent(url)) + return feed.entries + except ExpatError: + return [] # MODULE INTERFACE ####################################################