view feedupdate-main.py @ 220:e079faa547b8 python3

close the python3 branch - it does not contain any work worth kepping
author Dirk Olmes <dirk@xanthippe.ping.de>
date Thu, 22 May 2014 04:52:57 +0200
parents e50d446f9942
children
line wrap: on
line source

#!/usr/bin/env python3

import Database
from datetime import datetime, timedelta
from Feed import Feed
import FeedUpdater
import logging
import Mapping
from sqlalchemy.sql import and_
import sys
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

def checkPythonVersion():
    version = sys.version_info
    if version[0] < 3:
        print("feedupdate-main must run on Python 3")
        sys.exit(1)

if __name__ == "__main__":
    checkPythonVersion()
    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()