from os import environ
from urllib2 import urlopen

from flask import Flask, json, jsonify
app = Flask(__name__)

from hip import get_ranking_array

url = 'http://open.mapquestapi.com/directions/v2/route'
params = '?key={apikey}&ambiguities=ignore&routeType=pedestrian'
rel = url + params + '&from={flat},{flng}&to={tlat},{tlng}'


@app.route("/route/<from_lat>,<from_lng>/<to_lat>,<to_lng>")
def route(from_lat, from_lng, to_lat, to_lng):
    resp = urlopen(rel.format(apikey=environ['MAPQUEST_API_KEY'],
                   flat=from_lat, flng=from_lng, tlat=to_lat, tlng=to_lng))

    route = json.loads(resp.read().decode("utf-8"))
    coords = [(man['startPoint']['lat'], man['startPoint']['lng'])
              for leg in route['route']['legs']
              for man in leg['maneuvers']]
    hip_rank, total_rank = get_ranking_array(coords)
    return jsonify(route=route, hip_rank=list(hip_rank), total_rank=total_rank)

if __name__ == "__main__":
    app.run(debug=environ.get('FLASK_DEBUG', False))

from os import environ
from urllib2 import urlopen

from flask import Flask, json, make_response
app = Flask(__name__)

url = 'http://open.mapquestapi.com/directions/v2/route'
params = '?key={apikey}&ambiguities=ignore&routeType=pedestrian'
rel = url + params + '&from={flat},{flng}&to={tlat},{tlng}'


@app.route("/route/<from_lat>,<from_lng>/<to_lat>,<to_lng>")
def get_coords(from_lat, from_lng, to_lat, to_lng):
    resp = urlopen(rel.format(apikey=environ['MAPQUEST_API_KEY'],
                   flat=from_lat, flng=from_lng, tlat=to_lat, tlng=to_lng))

    resp_dict = json.loads(resp.read().decode("utf-8"))
    res = [(man['startPoint']['lat'], man['startPoint']['lng'])
           for leg in resp_dict['route']['legs']
           for man in leg['maneuvers']]
    return make_response(json.dumps(res))

if __name__ == "__main__":
    app.run(debug=environ.get('FLASK_DEBUG', False))

--- 
+++ 
@@ -1,8 +1,10 @@
 from os import environ
 from urllib2 import urlopen
 
-from flask import Flask, json, make_response
+from flask import Flask, json, jsonify
 app = Flask(__name__)
+
+from hip import get_ranking_array
 
 url = 'http://open.mapquestapi.com/directions/v2/route'
 params = '?key={apikey}&ambiguities=ignore&routeType=pedestrian'
@@ -10,15 +12,16 @@
 
 
 @app.route("/route/<from_lat>,<from_lng>/<to_lat>,<to_lng>")
-def get_coords(from_lat, from_lng, to_lat, to_lng):
+def route(from_lat, from_lng, to_lat, to_lng):
     resp = urlopen(rel.format(apikey=environ['MAPQUEST_API_KEY'],
                    flat=from_lat, flng=from_lng, tlat=to_lat, tlng=to_lng))
 
-    resp_dict = json.loads(resp.read().decode("utf-8"))
-    res = [(man['startPoint']['lat'], man['startPoint']['lng'])
-           for leg in resp_dict['route']['legs']
-           for man in leg['maneuvers']]
-    return make_response(json.dumps(res))
+    route = json.loads(resp.read().decode("utf-8"))
+    coords = [(man['startPoint']['lat'], man['startPoint']['lng'])
+              for leg in route['route']['legs']
+              for man in leg['maneuvers']]
+    hip_rank, total_rank = get_ranking_array(coords)
+    return jsonify(route=route, hip_rank=list(hip_rank), total_rank=total_rank)
 
 if __name__ == "__main__":
     app.run(debug=environ.get('FLASK_DEBUG', False))
Return route, hip rank and total rank
