0.9.1-2 for extras-devel
[feedingit] / psa_harmattan / feedingit / deb_dist / feedingit-0.1.0 / debian / feedingit / usr / share / feedingit / rss_sqlite.py
index 68797cd..bcefd42 100644 (file)
@@ -392,13 +392,13 @@ class Feed(BaseObject):
                 logger.debug("%s: No changes to feed." % (self.key,))
                 mainthread.execute(wc_success, async=True)
                 success = True
-            elif len(tmp["entries"])==0 and not tmp.version:
+            elif len(tmp["entries"])==0 and not tmp.get('version', None):
                 # An error occured fetching or parsing the feed.  (Version
                 # will be either None if e.g. the connection timed our or
                 # '' if the data is not a proper feed)
                 logger.error(
                     "Error fetching %s: version is: %s: error: %s"
-                    % (url, str (tmp.version),
+                    % (url, str (tmp.get('version', 'unset')),
                        str (tmp.get ('bozo_exception', 'Unknown error'))))
                 logger.debug(tmp)
                 def register_stream_update_failed(http_status):
@@ -456,8 +456,6 @@ class Feed(BaseObject):
                #reversedEntries = self.getEntries()
                #reversedEntries.reverse()
     
-               ids = self.getIds()
-    
                tmp["entries"].reverse()
                for entry in tmp["entries"]:
                    # Yield so as to make the main thread a bit more
@@ -493,13 +491,29 @@ class Feed(BaseObject):
                                 "date":date, "link":entry["link"], "author":entry["author"], "id":entry["id"]}
                    id = self.generateUniqueId(tmpEntry)
                    
-                   current_version \
-                       = self.db.execute('select date from feed where id=?',
-                                         (id,)).fetchone()
+                   current_version = self.db.execute(
+                       'select date, ROWID from feed where id=?',
+                       (id,)).fetchone()
                    if (current_version is not None
                        and current_version[0] == date):
                        logger.debug("ALREADY DOWNLOADED %s (%s)"
                                     % (entry["title"], entry["link"]))
+                       ## This article is already present in the feed listing. Update the "updated" time, so it doesn't expire                                                      
+                       self.db.execute("UPDATE feed SET updated=? WHERE id=?;",(currentTime,id))                                                                                    
+                       try:                                                                                                                                                         
+                           logger.debug("Updating already downloaded files for %s" %(id))                                                                                           
+                           filename = configdir+self.key+".d/"+id+".html"                                                                                                           
+                           file = open(filename,"a")                                                                                                                                
+                           utime(filename, None)                                                                                                                                    
+                           file.close()                                                                                                                                             
+                           images = self.db.execute("SELECT imagePath FROM images where id=?;", (id, )).fetchall()                                                                  
+                           for image in images:                                                                                                                                     
+                                file = open(image[0],"a")                                                                                                                           
+                                utime(image[0], None)                                                                                                                               
+                                file.close()                                                                                                                                        
+                       except:                                                                                                                                                      
+                           logger.debug("Error in refreshing images for %s" % (id))                                                                                                 
+                       self.db.commit()
                        continue                       
 
                    if current_version is not None:
@@ -522,7 +536,7 @@ class Feed(BaseObject):
                        self.serial_execution_lock.release ()
                        have_serial_execution_lock = False
                        for img in images:
-                           if not 'src' in img:
+                           if not img.has_key('src'):
                                continue
 
                            filename = self.addImage(
@@ -547,29 +561,27 @@ class Feed(BaseObject):
                    file = open(tmpEntry["contentLink"], "w")
                    file.write(soup.prettify())
                    file.close()
-                   if id in ids:
-                       self.db.execute("UPDATE feed SET updated=? WHERE id=?;", (currentTime, id) )
-                       self.db.commit()
-                   else:
-                       values = (id, tmpEntry["title"], tmpEntry["contentLink"], tmpEntry["date"], currentTime, tmpEntry["link"], 0)
-                       self.db.execute("INSERT INTO feed (id, title, contentLink, date, updated, link, read) VALUES (?, ?, ?, ?, ?, ?, ?);", values)
-                       self.db.commit()
-#                   else:
-#                       try:
-#                           self.db.execute("UPDATE feed SET updated=? WHERE id=?;", (currentTime, id) )
-#                           self.db.commit()
-#                           filename = configdir+self.key+".d/"+id+".html"
-#                           file = open(filename,"a")
-#                           utime(filename, None)
-#                           file.close()
-#                           images = self.db.execute("SELECT imagePath FROM images where id=?;", (id, )).fetchall()
-#                           for image in images:
-#                                file = open(image[0],"a")
-#                                utime(image[0], None)
-#                                file.close()
-#                       except:
-#                           pass
-    
+
+                   values = {'id': id,
+                             'title': tmpEntry["title"],
+                             'contentLink': tmpEntry["contentLink"],
+                             'date': tmpEntry["date"],
+                             'updated': currentTime,
+                             'link': tmpEntry["link"],
+                             'read': 0}
+
+                   if current_version is not None:
+                       # This is an update.  Ensure that the existing
+                       # entry is replaced.
+                       values['ROWID'] = current_version[1]
+
+                   cols, values = zip(*values.items())
+                   self.db.execute(
+                       "INSERT OR REPLACE INTO feed (%s) VALUES (%s);"
+                       % (','.join(cols), ','.join(('?',) * len(values))),
+                       values)
+                   self.db.commit()
+
                    # Register the object with Woodchuck and mark it as
                    # downloaded.
                    def register_object_transferred(