Example #1
0
def checkup():
    '''earn two more points for staying on campus'''
    try:
        coords = json.loads(request.data)
        if utils.check_distance(**coords)['distance'] > .378788:    # .378788 miles = 2000 feet
            return jsonify({'error':\
                            '''
                            You are not on campus. You will be checked
                            out if you don't return in five minutes.
                            '''})

        if not user.custom_data['checked_in']:
            return jsonify({'error': 'you are not checked in'})

        check_res = utils.check_points(user)
        if isinstance(check_res, dict):
            return jsonify(check_res)

        #if utils.check_wifi():
        user.custom_data['last_point'] = utils.current_time()
        user.custom_data['points'] += 2
        name = user.given_name
        return jsonify({'status': '%s just earned two more points' % name})
        # else:
            # return jsonify({'error': 'not logged into school wifi'})

    except (OSError, IOError) as excp:
        return jsonify({'error': excp.message})

    finally:
        user.custom_data.save()
Example #2
0
def checkin():
    '''checkin to campus'''
    try:
        cust = user.custom_data
        coords = json.loads(request.data)
        if utils.check_distance(**coords)['distance'] > .378788:    # .378788 miles = 2000 feet
            return jsonify({'error': 'you are not on campus'})

        if cust['checked_in']:
            return jsonify({'error': 'you are already checked in'})

        else:
            check_res = utils.check_points(user)
            if isinstance(check_res, dict):
                return jsonify(check_res)

        # if utils.check_wifi():
        user.custom_data['checked_in'] = True
        user.custom_data['points'] += 10
        user.custom_data['last_point'] = utils.current_time()
        return jsonify({'status': 'you are now checked into campus'})

        # return jsonify({'error': 'not logged into school wifi'})

    except (OSError, IOError) as excp:
        return jsonify({'error': excp.message})

    finally:
        user.custom_data.save()