Skip to content
Snippets Groups Projects
Unverified Commit cf7a5d39 authored by Sebastian Höffner's avatar Sebastian Höffner
Browse files

Adding versioning information to the JSON response.

parent 5f6796fb
No related branches found
No related tags found
No related merge requests found
import json
import uuid
from flask import Flask, render_template, request, redirect
......@@ -22,12 +23,25 @@ def is_non_gui_agent(ua_string):
return any(ua in ua_string for ua in uas)
def create_response(sentence):
content = wccg.parse(sentence)
response = {
'version': '1.0.0',
'application': 'web-openccg',
'uuid': str(uuid.uuid4())
}
response.update(content)
return response
@app.route('/gui', methods=['GET', 'POST'])
def gui():
"""Presents a simple input form to a browser user.
"""
sentence = request.form.get('sentence')
response = wccg.parse(sentence)
response = create_response(sentence)
response = json.dumps(response, indent=4)
return render_template('form.html', sentence=sentence, response=response)
......@@ -59,7 +73,7 @@ def index():
# The first key could be send e.g. by
# curl --data "This is the sentence." 127.0.0.1:5000
sentence = request.form.get(key) or key
response = wccg.parse(sentence)
response = create_response(sentence)
return json.dumps(response), response['http_status']
return redirect('/gui', code=307)
......
......@@ -92,6 +92,5 @@ def _as_dict(response):
parses[key] = ' '.join(parse)
return dict(sentence=sentence[1:-1],
number=num_parses,
parses=parses,
http_status=200)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment