When creating a unique id for an article, use all available information.
authorNeal H. Walfield <neal@gnu.org>
Sun, 24 Jul 2011 22:29:01 +0000 (00:29 +0200)
committerNeal H. Walfield <neal@walfield.org>
Sun, 31 Jul 2011 19:58:35 +0000 (21:58 +0200)
src/rss_sqlite.py

index 6735468..e73cc4d 100644 (file)
@@ -496,14 +496,30 @@ class Feed:
         return self.db.execute("SELECT date FROM feed WHERE id=?;", (id,) ).fetchone()[0]
     
     def generateUniqueId(self, entry):
-        if(entry["id"] != None):
-            return getId(str(entry["id"]))
-        else:
-            try:
-                return getId(str(entry["date"]) + str(entry["title"]))
-            except:
-                #print entry["title"]
-                return getId(str(entry["date"]))
+        """
+        Generate a stable identifier for the article.  For the same
+        entry, this should result in the same identifier.  If
+        possible, the identifier should remain the same even if the
+        article is updated.
+        """
+        # Prefer the entry's id, which is supposed to be globally
+        # unique.
+        key = entry.get('id', None)
+        if not key:
+            # Next, try the link to the content.
+            key = entry.get('link', None)
+        if not key:
+            # Ok, the title and the date concatenated are likely to be
+            # relatively stable.
+            key = entry.get('title', None) + entry.get('date', None)
+        if not key:
+            # Hmm, the article's content will at least guarantee no
+            # false negatives (i.e., missing articles)
+            key = entry.get('content', None)
+        if not key:
+            # If all else fails, just use a random number.
+            key = str (random.random ())
+        return getId (key)
     
     def getIds(self, onlyUnread=False):
         if onlyUnread: