X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=www%2Fmaps%2Fmaps%2Fcontrollers%2Fdirections.py;h=dab8f6630930ac2a2a9b60e907e0584254b9ef6f;hb=fe0f334b28cb0c3ed774e86c6067be8382f6c79e;hp=eabdfd49da36c155787b72a96ba986ee19ee7e1a;hpb=5485afbd4da2182072ef9756c65137729bf1eee5;p=dead%2Fcensus-tools.git diff --git a/www/maps/maps/controllers/directions.py b/www/maps/maps/controllers/directions.py index eabdfd4..dab8f66 100644 --- a/www/maps/maps/controllers/directions.py +++ b/www/maps/maps/controllers/directions.py @@ -73,7 +73,7 @@ class DirectionsController(BaseController): def json_to_kml(self): - directions_array = json.loads(request.POST['directions_result']) + directions_array = json.loads(request.POST['data']) placemarks = [] for result in directions_array: placemarks += self.directions_result_to_placemarks(result) @@ -86,3 +86,33 @@ class DirectionsController(BaseController): response.headers['Content-disposition'] = 'attachment; filename=routes.kml' return doc.to_kml() + + def directions_result_to_csv(self, result): + row = '' + + for trip in result['trips']: + + for route in trip['routes']: + route_start = self.get_route_address(route, True) + route_end = self.get_route_address(route, False) + row += '"' + route_start + '"' + row += ', ' + row += '"' + route_end + '"' + row += ', ' + row += str(float(route['distance']['value']) / 1000) + row += "\n" + + return row + + + def distances(self): + directions_array = json.loads(request.POST['data']) + csv = '' + + for result in directions_array: + csv += self.directions_result_to_csv(result) + + response.content_type = 'text/csv' + response.headers['Content-disposition'] = 'attachment; filename=distances.csv' + return csv +