PDF reading with python
This commit is contained in:
34
python/src/app.py
Normal file
34
python/src/app.py
Normal 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')
|
Reference in New Issue
Block a user