Ejemplo n.º 1
0
def generateRoom(room_id=None, type=1):
    # if no room id, generate a random one

    # set room type
    redis_db.set('room:%s:type' % room_id, type)

    # get topic id
    t_id = Question.getRandomIndex([])
    redis_db.rpush('room:%s:topics_seen' % room_id, t_id)

    redis_db.set('room:%s:topic_id' % room_id, t_id)
Ejemplo n.º 2
0
def getNewRoomQuestion():
    cid = redis_db.get('sid:%s:cid' % request.sid).decode('utf-8')
    room_id = redis_db.get('client:%s:room_id' % cid).decode('utf-8')

    used = redis_db.lrange('room:%s:topics_seen' % room_id, 0, -1)
    used = [(int(x)) for x in used]

    id = Question.getRandomIndex(used)
    q = Question.get(id)

    redis_db.set('room:%s:topic_id' % room_id, id)
    redis_db.rpush('room:%s:topics_seen' % room_id, id)

    emit('message', {'type': 'q', 'question': q, 'id': id}, room=room_id)