Esempio n. 1
0
def apirouting(mode, city, departure, arrival, time, people):
    '''
    Return a list of routes in polyline format.
    String adresses are not supported because they
    won't be needed for the mobile apps. Indeed the
    departure will be the same as the arrival because
    the mobile apps do not include full trips.

    Example URL:

        /routing/mode=takeBike&city=Toulouse&
        departure=[43.5639677,1.4655774]&
        arrival=[43.6044328,1.443463]&
        time=[1442935490355]&people=1

    Don't forget to remove all the spaces.
    '''
    if key == tools.read_json('config/keys.json')['routing']:
        situation = {
            'city': city,
            'departure': eval(departure),
            'arrival': eval(arrival),
            'time': eval(time),
            'people': int(people)
        }
        if mode == 'fullTrip':
            routes = routing.full_trip(situation)
        elif mode == 'takeBike':
            routes = routing.take_bike(situation)
        elif mode == 'dropBike':
            routes = routing.drop_bike(situation)
        return jsonify({'routes': routes})
    else:
        return jsonify({'error': 'Wrong API key.'})
Esempio n. 2
0
def route():
    data = json.loads(request.data.decode())
    situation = {
        'city': data['city'],
        'departure': data['departure'],
        'arrival': data['arrival'],
        'people': int(data['people']),
        'time': data['time']
    }
    mode = data['mode']
    # Build the paths according to the travelling mode
    if mode == 'fullTrip':
        routes = routing.full_trip(situation)
    elif mode == 'takeBike':
        routes = routing.take_bike(situation)
    elif mode == 'dropBike':
        routes = routing.drop_bike(situation)
    return jsonify({'routes': routes})