If a new feed's title is '', don't abort: set the title to that in the feed.
[feedingit] / src / rss_sqlite.py
index b3dc2b0..6735468 100644 (file)
@@ -443,9 +443,14 @@ class Feed:
                 if not success:
                     etag = None
                     modified = None
+                title = None
+                try:
+                    title = tmp.feed.title
+                except (AttributeError, UnboundLocalError), exception:
+                    pass
                 if postFeedUpdateFunc is not None:
                     postFeedUpdateFunc (self.key, updateTime, etag, modified,
-                                        *postFeedUpdateFuncArgs)
+                                        title, *postFeedUpdateFuncArgs)
 
     def setEntryRead(self, id):
         self.db.execute("UPDATE feed SET read=1 WHERE id=?;", (id,) )
@@ -808,7 +813,7 @@ class Listing:
     def _queuePostFeedUpdate(self, *args, **kwargs):
         mainthread.execute (self._postFeedUpdate, async=True, *args, **kwargs)
 
-    def _postFeedUpdate(self, key, updateTime, etag, modified):
+    def _postFeedUpdate(self, key, updateTime, etag, modified, title):
         if modified==None:
             modified="None"
         else:
@@ -817,6 +822,10 @@ class Listing:
             self.db.execute("UPDATE feeds SET updateTime=?, etag=?, modified=? WHERE id=?;", (updateTime, etag, modified, key) )
         else:
             self.db.execute("UPDATE feeds SET etag=?, modified=? WHERE id=?;", (etag, modified, key) )
+
+        if title is not None:
+            self.db.execute("UPDATE feeds SET title=(case WHEN title=='' THEN ? ELSE title END) where id=?;",
+                            (title, key))
         self.db.commit()
         self.updateUnread(key)
         
@@ -846,7 +855,10 @@ class Listing:
         return self.db.execute("SELECT unread FROM feeds WHERE id=?;", (key,)).fetchone()[0]
         
     def getFeedTitle(self, key):
-        return self.db.execute("SELECT title FROM feeds WHERE id=?;", (key,)).fetchone()[0]
+        (title, url) = self.db.execute("SELECT title, url FROM feeds WHERE id=?;", (key,)).fetchone()
+        if title:
+            return title
+        return url
         
     def getFeedUrl(self, key):
         return self.db.execute("SELECT url FROM feeds WHERE id=?;", (key,)).fetchone()[0]
@@ -918,7 +930,7 @@ class Listing:
 
     def addFeed(self, title, url, id=None, category=1):
         if not id:
-            id = getId(title)
+            id = getId(url)
         count = self.db.execute("SELECT count(*) FROM feeds WHERE id=?;", (id,) ).fetchone()[0]
         if count == 0:
             max_rank = self.db.execute("SELECT MAX(rank) FROM feeds;").fetchone()[0]