Beispiel #1
0
def cache_vote(number):
    """
    Increments the cached votes for this song.
    """
    previous_votes_cache = db.select("songs", where="number=$number", vars=locals())[0]['votes_cache']
    if not previous_votes_cache:
        previous_votes_cache = 0
    db.update("songs", where="number=$number", votes_cache=previous_votes_cache+1, vars=locals())
Beispiel #2
0
def songs_array(order='number'):
    """
    Returns an array of information for each song in the database.
    """
    songs = []
    for row in db.select('songs', order=order):
        votes = row['votes_cache']
        songs.append((row['title'], row['keyword'], row['number'], votes))
    return songs
Beispiel #3
0
def songs_dict(order='number'):
    """
    Returns an array of songs with each song's info in a dict.
    """
    songs = []
    position = 0
    for row in db.select('songs', order=order):
        songs.append({
            'position' : position,
            'title' : row['title'],
            'keyword' : row['keyword'],
            'number' : row['number'],
            'votes' : row['votes_cache']
        })
        position += 1
    return songs
Beispiel #4
0
def session_info(tropo_call_id):
    return db.select("sessions", where="tropo_call_id=$tropo_call_id", vars=locals())[0]
Beispiel #5
0
def song_title(number):
    """
    Returns the song title for a given song number.
    """
    if number:
        return db.select("songs", where="number=$number", vars=locals())[0]["title"]
Beispiel #6
0
def votes_array():
    votes = []
    for row in db.select('votes', order='id'):
        votes.append([row['id'], row['song_number'], row['phone_number']])
    return votes