From 763ca8a7c61621dd8835160189b308b66365b110 Mon Sep 17 00:00:00 2001 From: Kikimanox Date: Mon, 11 Jul 2022 15:27:46 +0200 Subject: [PATCH] Dodana vrsta oz. semafor pri obdelovanju conllu datotek --- swagger_server/controllers/oss_controller.py | 18 +++++++----------- swagger_server/util.py | 4 ++++ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/swagger_server/controllers/oss_controller.py b/swagger_server/controllers/oss_controller.py index ae0ad79..a21d0d5 100644 --- a/swagger_server/controllers/oss_controller.py +++ b/swagger_server/controllers/oss_controller.py @@ -18,17 +18,10 @@ def get_conllu(file_id): # noqa: E501 :rtype: str """ - file_path = util.get_conllu_path_by_id(file_id) - - a = Ngrams_Manager.get_by_file_id(file_id) - print(a) - try: - return send_file(file_path, attachment_filename=f'{file_id}.conllu', as_attachment=True) - except Exception as e: - if "The system cannot find the file specified" in str(e): - return "The conllu with this ID doesn't exist.", 404 - return str(e), 400 + return send_file(util.get_conllu_path_by_id(file_id), attachment_filename=f'{file_id}.conllu') + except FileNotFoundError as e: + return "The conllu with this ID doesn't exist.", 404 def get_conllus(leta, vrste, kljucnebesede, cerifpodrocja): # noqa: E501 @@ -149,4 +142,7 @@ def oss_besedilo_po_id_get(file_id): # noqa: E501 :rtype: str """ - return 'do some magic!' + try: + return send_file(util.get_original_file_by_id(file_id), attachment_filename=f'{file_id}.conllu') + except FileNotFoundError as e: + return "The conllu with this ID doesn't exist.", 404 diff --git a/swagger_server/util.py b/swagger_server/util.py index 381939e..53e5aac 100644 --- a/swagger_server/util.py +++ b/swagger_server/util.py @@ -144,3 +144,7 @@ def _deserialize_dict(data, boxed_type): def get_conllu_path_by_id(file_id): return f'..\\mnt\\ssd\\ds_ftp\\classla_OS2022\\conll\\rsdo_doc-{file_id}.plainText.conllu' + + +def get_original_file_by_id(file_id): + return f'..\\mnt\\ssd\\ds_ftp\\classla_OS2022\\conll\\rsdo_doc-{file_id}.xml'