view feedupdate-main.py @ 94:a16c4e2b2c55

rename some parameters to be in line with the pyqt docs
author Dirk Olmes <dirk@xanthippe.ping.de>
date Mon, 27 Dec 2010 08:30:09 +0100
parents d20e99d46d78
children e50d446f9942 bf22b32ae9f7
line wrap: on
line source

#!/usr/bin/env python

import Database
from datetime import datetime, timedelta
from Feed import Feed
import FeedUpdater
import logging
import Mapping
from sqlalchemy.sql import and_
import util

logger = logging.getLogger("feedupdater")

def listFeeds(session):
    allFeeds = session.query(Feed)
    for feed in allFeeds:
        logger.info("feed: " + feed.name)
        for entry in feed.entries:
            print entry.title

def expireFeedEntries(session):
    expireDate = _calculateExpireDate()
    logger.info("expiring entries older than " + str(expireDate))
    feedEntry = Mapping.feedEntryTable
    deleteStatement = feedEntry.delete().where(
        and_(feedEntry.c.create_timestamp < expireDate, feedEntry.c.read == 1)
    )
    deleteStatement.execute()

def _calculateExpireDate():
    now = datetime.now()
    delta = timedelta(days=30)
    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()