X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=www%2Fmaps%2Fmaps%2Fcontrollers%2Fdirections.py;h=0cd278ffa6893dfcbf741037339c2c289b77c5f0;hb=a35db4b9616635ac041a24d4af969a3fed67f354;hp=4c765a3dad217bc4e428eb73122a4a073fe5bae3;hpb=c0a23c3492a4aa7eefa21c8c5f2a4037000a9493;p=dead%2Fcensus-tools.git diff --git a/www/maps/maps/controllers/directions.py b/www/maps/maps/controllers/directions.py index 4c765a3..0cd278f 100644 --- a/www/maps/maps/controllers/directions.py +++ b/www/maps/maps/controllers/directions.py @@ -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): + rows = [] + + 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) + rows.append(row) + + return rows + + + def distances(self): + directions_array = json.loads(request.POST['data']) + csv_rows = [] + + for result in directions_array: + csv_rows += self.directions_result_to_csv(result) + + response.content_type = 'text/csv' + response.headers['Content-disposition'] = 'attachment; filename=distances.csv' + return "\n".join(csv_rows) +