예제 #1
0
def matchSong(score):
    strscore = '!' + str(score)
    if redisDB.r.get(strscore):
        strsonglist = redisDB.toString(redisDB.r.get(strscore))
        songlist = strsonglist.split(', ')
        song = random.choice(songlist)
        return song
    else:
        for i in range(
                1, 9
        ):  # If the score is not found in the songs database, it will modify the passed score until one is found
            newscore = (
                (score * 10) + i
            ) / 10  # This arithmetic circumvents Python's wonky floating point division problems introducing aditional decimal places.
            strscore = '!' + str(newscore)
            if redisDB.r.get(strscore):
                strsonglist = redisDB.toString(redisDB.r.get(strscore))
                songlist = strsonglist.split(', ')
                song = random.choice(songlist)
                return song
            else:
                newscore = ((score * 10) - i) / 10
                strscore = '!' + str(newscore)
                if redisDB.r.get(strscore):
                    strsonglist = redisDB.toString(redisDB.r.get(strscore))
                    songlist = strsonglist.split(', ')
                    song = random.choice(songlist)
                    return song
예제 #2
0
def isBListed(username, listed):
    blacklist = redisDB.toString(redisDB.r.hget(username, 'bl'))
    bList = blacklist[1:-1].split(', ')
    if listed in bList:
        return True
    else:
        return False
예제 #3
0
def addEntry(username, id):
    entries = redisDB.toString(redisDB.r.hget(username, 'entries'))
    if entries != "{}":
        entries = entries[0:-1] + ', ' + id + '}'
    else:
        entries = '{' + id + '}'
    redisDB.r.hset(username, 'entries', entries)
예제 #4
0
def deleteAccount(username):
    entries = redisDB.toString(redisDB.r.hget(username, "entries"))
    eList = entries[1:-1].split(", ")
    for entry in eList:
        redisDB.r.delete(entry)

    redisDB.r.delete(username)
예제 #5
0
def getAllEntries(username):
    entries = redisDB.toString(redisDB.r.hget(username, "entries"))
    eList = entries[1:-1].split(", ")

    if eList == ['']:
        eList = []

    return eList
예제 #6
0
def removeBListed(username, listed):
    if isBListed(username, listed):
        blacklist = redisDB.toString(redisDB.r.hget(username, 'bl'))
        bList = blacklist[1:-1].split(', ')
        bList.remove(listed)
        blacklist = '{' + ', '.join(bList) + '}'
        redisDB.r.hset(username, 'bl', blacklist)
        return True
    else:
        return False
예제 #7
0
def removeEntry(username, id):
    entries = redisDB.toString(redisDB.r.hget(username, 'entries'))
    eList = entries[1:-1].split(', ')
    if id in eList: # Check that the entry to be removed exists in the list.
        eList.remove(id)
        entries = '{' + ', '.join(eList) + '}'
        redisDB.r.hset(username, 'entries', entries)
        return True
    else:
        return False
예제 #8
0
def addBListed(username, listed):
    if not isBListed(username, listed):
        blacklist = redisDB.toString(redisDB.r.hget(username, 'bl'))
        if blacklist != "{}":
            blacklist = blacklist[0:-1] + ', ' + listed + '}'
        else:
            blacklist = '{' + listed + '}'
        redisDB.r.hset(username, 'bl', blacklist)
        return True
    else:
        return False
예제 #9
0
def shareMood(username, id):
    entries = redisDB.toString(redisDB.r.hget(username, "entries"))
    if entries != '{}':
        eList = entries[1:-1].split(", ")
    else:
        eList = []

    # Check if this entry has already been sent with different permissions.
    eid = '#' + id[1:]
    mid = '$' + id[1:]
    sid = '%' + id[1:]
    if eid in eList:
        eList.remove(eid)
    elif mid in eList:
        eList.remove(mid)
    elif sid in eList:
        eList.remove(sid)

    eList.append(mid)
    entries = '{' + ', '.join(eList) + '}'
    redisDB.r.hset(username, 'entries', entries)
예제 #10
0
def getBList(username):
    return redisDB.toString(redisDB.r.hget(username, "bl"))
예제 #11
0
def authorize(id, pw):
    if redisDB.r.hget(id, 'pw'):
        if pw == redisDB.toString(redisDB.r.hget(id, 'pw')):
            return True

    return False