Added new logic (temporary logic for getting files by search) and converting from files to txt

This commit is contained in:
Kikimanox
2022-08-29 22:53:49 +02:00
parent dd42b56c28
commit c8586513a9
6 changed files with 131 additions and 45 deletions
@@ -1,7 +1,13 @@
import connexion
import six
# import tika
from swagger_server import util
import pandas as pd
import docx
import codecs
import xml.etree.ElementTree as ET
from PyPDF2 import PdfReader
def datoteka_v_besedilo_post(file=None): # noqa: E501
@@ -14,7 +20,27 @@ def datoteka_v_besedilo_post(file=None): # noqa: E501
:rtype: str
"""
return 'do some magic!'
if file is None:
return "No file provided", 400
elif "openxmlformats-officedocument.wordprocessingml.document" in file.content_type:
content = [p.text for p in docx.Document(file).paragraphs]
elif "text/plain" in file.content_type:
content = file.read().decode('utf-8')
elif "application/pdf" in file.content_type:
reader = PdfReader(file)
content = '\n'.join([p.extract_text() for p in reader.pages])
content = "ZACASNO UPORABLJEN DRUGI BRALEC KOT TIKA, TA BO SE DODANA KASNEJE...\n\n" + content
elif "text/xml" in file.content_type:
root = ET.parse(file).getroot()
plainText = root.findall('PlainText')
if len(plainText) == 0:
return "Didn't find anything in PlainText", 400
content = '\n'.join([pt.text for pt in plainText])
else:
return "Currently supporing only docx, txt/plain, pdf, xml*... more will be added later", 501
return content, 200
def get_text_ocr(file=None): # noqa: E501
@@ -27,4 +53,4 @@ def get_text_ocr(file=None): # noqa: E501
:rtype: str
"""
return 'do some magic!'
return 'Not yet implemented'