Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BGDIINF_SB-2378: Corrected the CSV output #102

Merged
merged 1 commit into from
May 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions app/routes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import csv
import json
import logging
from io import StringIO

from shapely.geometry import Point
from werkzeug.exceptions import HTTPException
Expand Down Expand Up @@ -97,7 +99,17 @@ def profile_csv_route():
if "callback" in request.args:
abort(400, 'callback parameter not supported')
profile, status_code = _get_profile(False)
return str(profile), status_code, {'Content-Type': 'text/csv'}
csv.register_dialect(
'semi-colon', delimiter=';', quoting=csv.QUOTE_ALL, quotechar='"', lineterminator='\r\n'
)
buffer = StringIO()
writer = csv.writer(buffer, dialect='semi-colon')
# write header
writer.writerow(profile['headers'])
writer.writerows(profile['rows'])
buffer.seek(0)

return buffer.read(), status_code, {'Content-Type': 'text/csv'}


def _get_profile(output_to_json):
Expand Down Expand Up @@ -143,8 +155,11 @@ def _get_profile(output_to_json):
# need to add points closer to each other than the min resolution of 2m), we return HTTP 203 to
# notify that nb_points couldn't be match.
status_code = 200
if is_custom_nb_points and len(result) < nb_points:
if output_to_json and is_custom_nb_points and len(result) < nb_points:
status_code = 203
elif not output_to_json and is_custom_nb_points and len(result['rows']) < nb_points:
status_code = 203

return result, status_code


Expand Down