Commit fa9b1383 authored by gijs's avatar gijs

The cleaner backend

parent ee0b3965
from flask import Flask
from flask import Flask, jsonify, request
from classification_utils import db
import json
baseurl = '/the-cleaner/api'
app = Flask(__name__)
@app.route("{}/document".format(baseurl), methods=["GET"])
def get_document ():
conn = db.connect()
rows = db.get_document(conn)
# print(rows[0])
if rows:
return jsonify({
'document': rows[0]['document'],
'lines': [{
'document': r['document'],
'line': r['line'],
'sentence': r['sentence'],
'clean': r['clean'],
'clean_annotation': r['clean_annotation'],
'checked': r['checked'],
} for r in rows]
})
else:
return jsonify("Error")
@app.route("{}/update_sentence".format(baseurl), methods=["POST"])
def update_sentence():
conn = db.connect()
document = request.form['document']
line = request.form['line']
sentence = request.form['sentence']
clean = request.form['clean']
if db.update_sentence(conn, document, line, sentence, clean):
return jsonify("Done")
else:
return jsonify("Error")
@app.route("{}/update_document".format(baseurl), methods=["POST"])
def update_document():
conn = db.connect()
document = request.form['document']
lines = json.loads(request.form['lines'])
# print(document, lines)
# return jsonify("?")
if db.update_document(conn, document, lines):
return jsonify("Done")
else:
return jsonify("Error")
@app.route("{}/get_poem".format(baseurl), methods=["GET"])
def make_poem():
return jsonify("text")
@app.after_request
def add_headers(response):
response.headers.add('Access-Control-Allow-Origin', '*')
response.headers.add('Access-Control-Allow-Headers',
'Content-Type,Authorization')
return response
\ No newline at end of file
../../classification_utils
\ No newline at end of file
export FLASK_APP=app.py
export FLASK_ENV=development
flask run
\ No newline at end of file
flask
gunicorn
pattern
langdetect
pyspellchecker
csvwrite
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment