changeset 110:43c234c8fe87

store the number of days to keep feed entries as preference setting in the database. The feed update process reads and uses that value.
author Dirk Olmes <dirk@xanthippe.ping.de>
date Wed, 30 Mar 2011 02:59:22 +0200
parents bf22b32ae9f7
children c17a224bc251
files Preferences.py feedupdate-main.py
diffstat 2 files changed, 12 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/Preferences.py	Tue Mar 29 04:06:50 2011 +0200
+++ b/Preferences.py	Wed Mar 30 02:59:22 2011 +0200
@@ -2,6 +2,7 @@
 from Preference import Preference
 import util
 
+DAYS_TO_KEEP_FEED_ENTRIES = "DAYS_TO_KEEP_FEED_ENTRIES"
 HIDE_READ_ENTRIES = "HIDE_READ_FEED_ENTRIES"
 PROXY_HOST = "PROXY_HOST"
 PROXY_PORT = "PROXY_PORT"
@@ -67,3 +68,7 @@
     def isProxyConfigured(self):
         pref = self._cachedPreference(PROXY_HOST, addIfMissing=False)
         return pref is not None
+
+    def daysToKeepFeedEntries(self):
+        pref = self._cachedPreference(DAYS_TO_KEEP_FEED_ENTRIES, 90, addIfMissing=True)
+        return int(pref.value)
--- a/feedupdate-main.py	Tue Mar 29 04:06:50 2011 +0200
+++ b/feedupdate-main.py	Wed Mar 30 02:59:22 2011 +0200
@@ -6,6 +6,7 @@
 import FeedUpdater
 import logging
 import Mapping
+from Preferences import Preferences
 from sqlalchemy.sql import and_
 import util
 
@@ -19,7 +20,7 @@
             print entry.title
 
 def expireFeedEntries(session):
-    expireDate = _calculateExpireDate()
+    expireDate = _calculateExpireDate(session)
     logger.info("expiring entries older than " + str(expireDate))
     feedEntry = Mapping.feedEntryTable
     deleteStatement = feedEntry.delete().where(
@@ -27,20 +28,21 @@
     )
     deleteStatement.execute()
 
-def _calculateExpireDate():
+def _calculateExpireDate(session):
     now = datetime.now()
-    delta = timedelta(days=90)
+    daysToKeepFeedEntries = Preferences(session).daysToKeepFeedEntries()
+    delta = timedelta(days=daysToKeepFeedEntries)
     return now - delta
 
 if __name__ == "__main__":
     util.configureLogging()
     session = Database.createSession()
-    
+
     #util.loadFeeds(session)
     #util.forceUpdateAllFeeds(session)
     #listFeeds(session)
     #OpmlImport.createFeedsFromOPML(session, "feed-data/feeds.opml.xml")
     FeedUpdater.updateAllFeeds(session)
     expireFeedEntries(session)
-    
+
     session.close()