Exemple #1
0
def fivee():
    if request.method == 'POST':
        user = User.get_user_from_token(request.form['token'])
        if not user:
            abort(404)
        user.load()
        if user['status'] == "waiting":
            return jsonify({})
        user['lat'] = request.form['lat']
        user['lng'] = request.form['lng']
        if not user['lat'] or not user['lng']:
            abort(400)
        user.save()
        log.info("User %s want to be a fivee", user['username'])
        fiver_wait_list = User.get_wait_list('fiver')
        fiver_match = None
        fiver_distance = None
        for str_fiver in fiver_wait_list:
            fiver = json.loads(str_fiver)
            distance = user.distance(fiver['lat'], fiver['lng'])
            if fiver_distance is None or distance < fiver_distance:
                fiver_distance = distance
                fiver_match = str_fiver

        if fiver_distance is None or fiver_distance > MAX_FYVE_DISTANCE:
            # No matches
            user['match'] = "..."
            user['status'] = "waiting"
            user.save()
            User.insert_into_wait_list('fivee', json.dumps(user.wait_list_format))
            return jsonify({})

        # We found a match!
        User.remove_from_wait_list('fiver', fiver_match)
        fiver_match = User(json.loads(fiver_match)['username'])
        fiver_match.load()
        fiver_match['match'] = user['username']
        fiver_match['status'] = "matched"
        fiver_match.save()
        user['match'] = fiver_match['username']
        user['status'] = "matched"
        user.save()

        return jsonify(fiver_match.match_format)

    else:
        user = User.get_user_from_token(request.args['token'])
        if not user:
            abort(404)
        user.load()
        # Checking in for a match
        if user['match'] == "...":
            # Still waiting
            assert user['status'] == "waiting"
            return jsonify({})
        # We have a match!
        match_user = User(user['match'])
        match_user.load()
        return jsonify(match_user.match_format)
Exemple #2
0
def status():
    user = User.get_user_from_token(request.args['token'])
    if not user:
        abort(404)
    user.load()

    return jsonify(user.status_format)
Exemple #3
0
def rate():
    user = User.get_user_from_token(request.form['token'])
    if not user:
        abort(404)
    if not request.form['username'] or not request.form['rating']:
        abort(400)
    rated_user = User(request.form['username'])
    five_rating = request.form['rating']
    rated_user.rate(five_rating)
    log.info("User %s rated user %s with a %s", user['username'], rated_user['username'], five_rating)

    return jsonify({})
Exemple #4
0
def success():
    user = User.get_user_from_token(request.form['token'])
    if not user:
        abort(404)
    log.info("User %s is reporting a successful high five!", user['username'])
    user.load()
    user_fyved = User(user['match'])
    user_fyved.load()

    # F**k yeah!
    user['status'] = "fyved"
    user.save()
    user_fyved['status'] = "fyved"
    user_fyved.save()

    return jsonify({})
Exemple #5
0
def bail():
    user = User.get_user_from_token(request.form['token'])
    if not user:
        abort(404)
    log.info("User %s is bailing", user['username'])
    user.load()

    user_left_hanging = User(user['match'])
    user_left_hanging.load()
    user_left_hanging['status'] = "cancelled"
    user_left_hanging.save()

    user['status'] = "cancelled"
    user.save()

    return jsonify({})