From 8273b1488e0ec77902651d7b1351a0223d0ded5e Mon Sep 17 00:00:00 2001 From: Adam Sampson Date: Tue, 29 Jul 2003 10:59:28 +0000 Subject: [PATCH] Handle timeouts as errors too. Don't update the last-updated time when an error occurs. --- rawdoglib/rawdog.py | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/rawdoglib/rawdog.py b/rawdoglib/rawdog.py index 6954707..8d6a4b6 100644 --- a/rawdoglib/rawdog.py +++ b/rawdoglib/rawdog.py @@ -59,38 +59,40 @@ class Feed: if not force and (now - self.last_update) < (self.period * 60): return 0 - self.last_update = now + error = None try: p = feedparser.parse(self.url, self.etag, self.modified, "rawdog/" + VERSION) except: - print "Feed: " + self.url - print "Error parsing feed." - print - return 0 + error = "Error parsing feed." - status = p["status"] - message = None - if status == 301: + status = p.get("status") + if status is None: + error = "Timeout while reading feed." + elif status == 301: # Permanent redirect. The feed URL needs changing. - message = "New URL: " + p["url"] + "\n" - message += "The feed has moved permanently to a new URL.\n" - message += "You should update its entry in your config file." + error = "New URL: " + p["url"] + "\n" + error += "The feed has moved permanently to a new URL.\n" + error += "You should update its entry in your config file." elif status in [403, 410]: # The feed is disallowed or gone. The feed should be unsubscribed. - message = "The feed has gone.\n" - message += "You should remove it from your config file." + error = "The feed has gone.\n" + error += "You should remove it from your config file." elif status / 100 in [4, 5]: # Some sort of client or server error. The feed may need unsubscribing. - message = "The feed returned an error.\n" - message += "If this condition persists, you should remove it from your config file." + error = "The feed returned an error.\n" + error += "If this condition persists, you should remove it from your config file." - if message is not None: + if error is not None: print "Feed: " + self.url - print "HTTP Status: " + str(status) - print message + if status is not None: + print "HTTP Status: " + str(status) + print error print + return 0 + + self.last_update = now self.etag = p.get("etag") self.modified = p.get("modified") -- 2.35.1