PDF reading with python

This commit is contained in:
2021-11-01 11:00:59 -03:00
parent 9f301e2175
commit 5ee267568a
74 changed files with 1092 additions and 26 deletions

34
python/src/app.py Normal file
View File

@ -0,0 +1,34 @@
import json
import os
from flask import Flask, request
import contabilidad.pdf as pdf
import contabilidad.passwords as passwords
import contabilidad.log as log
app = Flask(__name__)
log.logging['filename'] = '/var/log/python/contabilidad.log'
@app.route('/pdf/parse', methods=['POST'])
def pdf_parse():
data = request.get_json()
if not isinstance(data['files'], list):
data['files'] = [data['files']]
password_file = '/app/config/.passwords.yml'
pwds = passwords.get_passwords(password_file)
texts = []
for file in data['files']:
filename = os.path.realpath(os.path.join('/app/data', file['filename']))
for p in pwds:
obj = pdf.get_text(filename, p)
if obj is None:
continue
print(obj)
texts.append(json.dumps(obj))
return json.dumps(texts)
if __name__ == '__main__':
app.run(host='0.0.0.0')