psa: remove old event feed items
[feedingit] / src / rss.py
index e82a4b5..66149d4 100644 (file)
@@ -33,6 +33,8 @@ import time
 import urllib2
 from BeautifulSoup import BeautifulSoup
 from urlparse import urljoin
+import logging
+logger = logging.getLogger(__name__)
 
 #CONFIGDIR="/home/user/.feedingit/"
 
@@ -88,7 +90,7 @@ class Feed:
                 f.close()
                 outf.close()
             except:
-                print "Could not download " + url
+                logger.error("Could not download " + url)
         else:
             #open(filename,"a").close()  # "Touch" the file
             file = open(filename,"a")
@@ -195,7 +197,7 @@ class Feed:
                             img['src']=filename
                             tmpEntry["images"].append(filename)
                           except:
-                              print "Error downloading image %s" % img
+                              logger.error("Error downloading image %s" % img)
                    tmpEntry["contentLink"] = configdir+self.uniqueId+".d/"+id+".html"
                    file = open(tmpEntry["contentLink"], "w")
                    file.write(soup.prettify())
@@ -234,7 +236,7 @@ class Feed:
                         tmpEntries[entryId] = self.entries[entryId]
                         tmpIds.append(entryId)
                     except:
-                        print "Error purging old articles %s" % entryId
+                        logger.error("Error purging old articles %s" % entryId)
                         self.removeEntry(entryId)
 
            self.entries = tmpEntries
@@ -280,7 +282,7 @@ class Feed:
                         #
                     except OSError:
                         #
-                        print 'Could not remove', file
+                        logger.error('Could not remove %s' % file)
            
 
     def extractContent(self, entry):
@@ -399,20 +401,21 @@ class Feed:
                 try:
                     remove(entry["contentLink"])  #os.remove
                 except:
-                    print "File not found for deletion: %s" % entry["contentLink"]
+                    logger.error("File not found for deletion: %s"
+                                 % entry["contentLink"])
             del self.entries[id]
         else:
-            print "Entries has no %s key" % id
+            logger.error("Entries has no %s key" % id)
         if id in self.ids:
             self.ids.remove(id)
         else:
-            print "Ids has no %s key" % id
+            logger.error("Ids has no %s key" % id)
         if self.readItems.has_key(id):
             if self.readItems[id]==False:
                 self.countUnread = self.countUnread - 1
             del self.readItems[id]
         else:
-            print "ReadItems has no %s key" % id
+            logger.error("ReadItems has no %s key" % id)
         #except:
         #    print "Error removing entry %s" %id
     
@@ -608,7 +611,7 @@ class Listing:
         except:
             # If the feed file gets corrupted, we need to reset the feed.
             import traceback
-            traceback.print_exc()
+            logger.error("getFeed: %s" % traceback.format_exc())
             import dbus
             bus = dbus.SessionBus()
             remote_object = bus.get_object("org.freedesktop.Notifications", # Connection name