Ejemplo n.º 1
0
def get_list_archive_game(firstdate, seconddate):
    """ returh list archive games

    - return dictionary in format:
              { 'date' : date,
                'players': user VS user }

    - `firstdate`: date from first field on archive.html
    - `seconddate`: date from second field on archive.html
    """
    if firstdate == '' and seconddate == '':
        games = Games.objects(status=2)
    elif seconddate == '' or firstdate == '':
        try:
            if firstdate and len(firstdate) == 10:
                year = int(firstdate[-4:])
                month = int(firstdate[3:5])
                day = int(firstdate[:2])
                dt = datetime.datetime(year, month, day)
                games = Games.objects(status=2, time_begin__gte=dt)
            elif seconddate and len(seconddate) == 10:
                year = int(seconddate[-4:])
                month = int(seconddate[3:5])
                day = int(seconddate[:2])
                dt = datetime.datetime(year, month, day)
                games = Games.objects(status=2, time_begin__gte=dt)
            else:
                return False
        except: 
            return False
    else:
        if len(firstdate) != 10 and len(seconddate) != 10:
            return False
        try:
            year_f = int(firstdate[-4:])
            month_f = int(firstdate[3:5])
            day_f = int(firstdate[:2])
            dt_first = datetime.datetime(year_f, month_f, day_f)
            year_s = int(seconddate[-4:])
            month_s = int(seconddate[3:5])
            day_s = int(seconddate[:2])
            dt_second = datetime.datetime(year_s, month_s, day_s)
            if dt_first < dt_second:
                dt_second = datetime.datetime(year_s, month_s, day_s, 23, 59, 59)
                games = Games.objects( Q(status=2) & (Q(time_begin__gte=dt_first) & Q(time_begin__lte=dt_second)))
            else:
                dt_first = datetime.datetime(year_f, month_f, day_f, 23, 59, 59)
                games = Games.objects( Q(status=2) & (Q(time_begin__lte=dt_first) & Q(time_begin__gte=dt_second)))
        except:
            return False
    if games:
        dict_game = {}
        for game in games:
            note = Logs.objects(game=game)[0]
            dict_game[str(note.game.id)] = { 'date' : note.game.time_begin.strftime('%d-%m-%Y'),
                                             'players': note.move_user + ' VS ' + note.opponent }
        return dict_game
    return True
Ejemplo n.º 2
0
def get_all_moves(id_game):
    """return list moves for game move
    
    Arguments:
    - `id_game`: id game
    """
    game = Games.objects.get(id=id_game)
    notes = Logs.objects(game=game).order_by('time')
    moves = {}
    count = 1
    for note in notes:
        moves[count] = str(note.id)
        count += 1
    return moves
Ejemplo n.º 3
0
def get_info_battle(game_id):
    """return dict:
    
    { 'user_field': field,
      'opponent_field': field ,
      'username': user_name ,
      'opponentname': user_name ,
      'game_status': status ,
      'time_begin': time_begin }
    
    Arguments:
    - `game_id`: id game
    """
    game = Games.objects.get(id=game_id)
    try:
        note = Logs.objects(game=game).order_by('-time')[0]
    except: 
        return False
    return get_info(note)