From: Eevee Date: Mon, 9 Aug 2010 03:36:01 +0000 (-0700) Subject: Don't toss old entries when an RSS feed is down. X-Git-Tag: veekun-promotions/2010082201~6 X-Git-Url: http://git.veekun.com/zzz-spline-frontpage.git/commitdiff_plain/e1e19c27da0c22e6b65a6e245f53f8a26739778e?hp=3e28142ab39f3b4f3080c8e55c76a66d8134bf66 Don't toss old entries when an RSS feed is down. --- diff --git a/splinext/frontpage/sources.py b/splinext/frontpage/sources.py index eaefc57..e28dc38 100644 --- a/splinext/frontpage/sources.py +++ b/splinext/frontpage/sources.py @@ -6,6 +6,7 @@ from collections import namedtuple import datetime import subprocess from subprocess import PIPE +from urllib2 import URLError import feedparser import lxml.html @@ -119,8 +120,13 @@ class CachedSource(Source): # Too early! return - updates = self._poll(self.limit, self.max_age) - cache.get_cache('spline-frontpage')[self.cache_key()] = updates + try: + updates = self._poll(self.limit, self.max_age) + cache.get_cache('spline-frontpage')[self.cache_key()] = updates + except Exception: + # Hmm, polling broke. Be conservative and don't do anything; old + # data is probably still OK for now + pass return @@ -161,6 +167,11 @@ class FeedSource(CachedSource): def _poll(self, limit, max_age): feed = feedparser.parse(self.feed_url) + if feed.bozo and isinstance(feed.bozo_exception, URLError): + # Feed is DOWN. Bail here; otherwise, old entries might be lost + # just because, say, Bulbanews is down yet again + raise feed.bozo_exception + if not self.title: self.title = feed.feed.title