Exemplo n.º 1
0
 def _randquote():
     quotecount = db_helper.fetchall(
         'SELECT COUNT(*) FROM `quotes`')[0][0]
     if quotecount == 0:
         return 'No quotes found'
     # Get the quote at a specific position
     quote = Quote.from_db_row(
         db_helper.fetchall('SELECT * FROM `quotes` LIMIT 1 OFFSET ?',
                            (random.randrange(0, quotecount), ))[0])
     return _presentquote(quote)
Exemplo n.º 2
0
def db_select_all():
    """
    Returns:
        list(Setting): List of all Settings
    """
    result = db_helper.fetchall(SELECT_ALL)
    return list(map(Setting.from_db_row, result))
Exemplo n.º 3
0
def db_select_one(qid):
    """Select the specified quote by the id"""
    rawquote = db_helper.fetchall(SELECT_ONE_STATEMENT, (qid, ))
    if rawquote is None or len(rawquote) == 0:
        return None
    else:
        return Quote.from_db_row(rawquote[0])
Exemplo n.º 4
0
def db_select_all():
    """Get all quotes in the database"""
    rawquotes = db_helper.fetchall(SELECT_ALL_STATEMENT)
    if rawquotes is None:
        return []
    else:
        return [Quote.from_db_row(row) for row in rawquotes]
Exemplo n.º 5
0
def db_select_for_module(module):
    """
    Args:
        module (str): The module name from the setting to load
    Returns:
        list(Setting): List of all matching Settings
    """
    result = db_helper.fetchall(SELECT_FOR_MODULE, (module, ))
    return list(map(Setting.from_db_row, result))
Exemplo n.º 6
0
def db_select_for_module_key(module, key):
    """
    Args:
        module (str): The module name from the setting to load
        key (str): The key name from the setting to load
    Returns:
        (Setting): The matching setting or None
    """
    result = db_helper.fetchall(SELECT_FOR_MODULE_KEY, (module, key))
    if len(result) == 0:
        return None
    else:
        return Setting.from_db_row(result[0])
Exemplo n.º 7
0
def db_get_all():
    all = db_helper.fetchall(SELECT_ALL_STATEMENT)
    return list(map(RegexResponse.fromdbtuple, all))
Exemplo n.º 8
0
def db_get_all():
    return list(
        map(TimedMessage.from_db_row,
            db_helper.fetchall(SELECT_ALL_STATEMENT)))
Exemplo n.º 9
0
def db_insert(tm):
    tm.id = db_helper.fetchall(
        INSERT_STATEMENT,
        (tm.message, tm.inittime, tm.looptime, 1 if tm.enabled else 0))[0][0]
Exemplo n.º 10
0
def db_get(id):
    result = db_helper.fetchall(SELECT_STATEMENT, (id, ))
    if len(result) > 0:
        return TimedMessage.from_db_row(result[0])
    else:
        return None
Exemplo n.º 11
0
def db_get_command(name):
    found = list(map(Command.from_db_tuple,db_helper.fetchall(GET_STATEMENT,(name,))))
    if len(found)==0:
        return None
    else:
        return found[0]
Exemplo n.º 12
0
def db_get_all_commands():
    return map(Command.from_db_tuple,db_helper.fetchall(GET_ALL_STATEMENT))