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
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
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)
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)
def getAllEntries(username): entries = redisDB.toString(redisDB.r.hget(username, "entries")) eList = entries[1:-1].split(", ") if eList == ['']: eList = [] return eList
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
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
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
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)
def getBList(username): return redisDB.toString(redisDB.r.hget(username, "bl"))
def authorize(id, pw): if redisDB.r.hget(id, 'pw'): if pw == redisDB.toString(redisDB.r.hget(id, 'pw')): return True return False