view util.py @ 123:862760b161b4 backend

restructured adding a feed so that only the URL is passed into the backend - the rest of the operation is backend-internal
author Dirk Olmes <dirk@xanthippe.ping.de>
date Mon, 22 Aug 2011 10:30:33 +0200
parents 04a730f9d07d
children c923e4c57a81
line wrap: on
line source


from Feed import Feed
from datetime import datetime, timedelta
import logging

logger = logging.getLogger("database")

# TODO remove this
#def databaseLoggingEnabled():
#    loggingEnabled = False
#    for arg in sys.argv:
#        if arg == "--databaseLogging":
#            loggingEnabled = True
#    return loggingEnabled

# TODO remove this
#def configureLogging():
#    logging.basicConfig(level=logging.DEBUG)
#
#    sqlalchemyLogLevel = logging.ERROR
#    if databaseLoggingEnabled():
#        sqlalchemyLogLevel = logging.INFO
#    logging.getLogger("sqlalchemy").setLevel(sqlalchemyLogLevel)
#
#    logging.getLogger("sqlalchemy.orm").setLevel(logging.WARN)

def loadFeeds(session=None, filename="feeds.txt"):
    file = open(filename)
    for line in file:
        (title, rss_url) = line.split("|")
        # remove the newline
        rss_url = rss_url.rstrip()
        feed = Feed(title, rss_url)
        session.add(feed)
    file.close()
    session.commit()

def forceUpdateAllFeeds(session=None):
    for feed in Feed.all(session):
        feed.next_update = datetime.now() - timedelta(minutes=1)
    session.commit()