Exemple #1
0
def get_local_rating(**options):
    db = DB()
    events, status, error = db.get_list_events(options['sport_id'])
    if status:
        return response_error(status, error)

    local_events = []

    for event in events:
        participants, status, error = db.get_event_participants(event)
        if status:
            return response_error(status, error)

        if all(elem in options['usernames'] for elem in participants):
            local_events.append(event)

    result = {username: 0 for username in options['usernames']}

    for event in local_events:
        for username in options['usernames']:
            res, status, error = db.get_user_result(username, event)
            if status:
                return response_error(status, error)

            if res == 'W':
                result[username] += 2

            if res == 'D':
                result[username] += 1

    return response_ok(result)
Exemple #2
0
def add_follow(**options):
    db = DB()
    user_id, status, error = db.auth(options['username'], options['password'])
    if status:
        return response_error(status, error)

    status, error = db.create_follow(user_id, options['sport_id'], options['location'])
    if status:
        return response_error(status, error)

    events, status, error = db.get_list_events(options['sport_id'], options['location'])
    if status:
        return response_error(status, error)

    suggested_events = []
    for event in events:
        participants, status, error = db.get_event_participants(event)
        if status:
            return response_error(status, error)

        if not options['username'] in participants:
            suggested_events.append(event)

    return response_ok({'event_ids': suggested_events})