Handle timeouts as errors too.
authorAdam Sampson <ats@offog.org>
Tue, 29 Jul 2003 10:59:28 +0000 (10:59 +0000)
committerAdam Sampson <ats@offog.org>
Tue, 29 Jul 2003 10:59:28 +0000 (10:59 +0000)
Don't update the last-updated time when an error occurs.

rawdoglib/rawdog.py

index 6954707ee61967c1d15d1a381a7226c7f9062b36..8d6a4b6bb8211d9941f5c5c5274cece4e534f5d4 100644 (file)
@@ -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")