implemented configurable housekeeping

This commit is contained in:
Ronald Schaten 2013-04-15 21:44:49 +02:00
parent f78b99e61e
commit 24209b4869

View File

@ -1,6 +1,6 @@
from sqlalchemy import Column, Integer, String, Boolean, Enum
from sqlalchemy.orm import relationship, backref
from datetime import datetime
from datetime import datetime, timedelta
import feedparser
import sys
@ -15,6 +15,7 @@ class Feed(Base):
id = Column(Integer, primary_key=True)
url = Column(String(255))
frequency = Column(Integer)
keepdaysafterlastfetch = Column(Integer, default=30)
daily = Column(Boolean)
resolveredirects = Column(Boolean)
readability = Column(Boolean)
@ -100,6 +101,16 @@ class Feed(Base):
self.entries.append(Entry(entry, self))
entries_new += 1
print 'updated %d of %d entries' % (entries_new, entries_total)
self.housekeeper(session)
def housekeeper(self, session):
count = 0
for entry in self.entries:
if entry.lastfetched < (datetime.now() - timedelta(days=self.keepdaysafterlastfetch)):
session.delete(entry)
count += 1
if count > 0:
print 'housekeeper deleted %d entries older than %d days.' % (count, self.keepdaysafterlastfetch)
def reset(self):
self.entries[:] = []