view util.py @ 62:abc0516a1c0c

FeedEntry provides a static method for creating new entries: better modularization and support for working with the class in interactive mode. FeedUpdater's normalize method is a module function now, again for ease of use in interactive scenarios
author dirk@xanthippe.ping.de
date Wed, 28 Jul 2010 20:30:34 +0200
parents 254d5b89a6ca
children 04a730f9d07d
line wrap: on
line source


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

logger = logging.getLogger("database")

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

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()

def str2bool(string):
    return string.lower() in ["yes", "true", "t", "1"]

def bool2str(bool):
    if bool:
        return "True"
    else:
        return "False"