Example #1
0
def get_watch_users(session_id):
    """return number user which watch game
    
    Arguments:
    - `session_id`: session_id
    """
    user = Users.objects.get(session=session_id)
    game = user.game
    now = datetime.datetime.now()
    time_old = now + datetime.timedelta(minutes = -1)
    return Watchusers.objects(game=game, time__gte=time_old).count()
Example #2
0
def update_watch_users(id_game, session_id):
    """update information about users which watch game
    
    Arguments:
    - `id_game`: id game
    - `session_id`: session id
    """
    now = datetime.datetime.now()
    time_old = now + datetime.timedelta(minutes = -1 )
    try:
        Watchusers.objects(time__lte=time_old).delete()
    except:
        pass
    user = Users.objects.get(session=session_id)
    game = Games.objects.get(id=id_game)
    watch_user = Watchusers.objects(user=user, game=game)
    if watch_user:
        watch_user[0].time = now
        watch_user[0].save()
    else:
        new_watch = Watchusers(user=user, game=game)
        new_watch.save()
    return True