-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.py
49 lines (35 loc) · 1.09 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python
import os
from flask import (Flask,
request,
jsonify,
render_template,
send_from_directory)
from src.parser import convertToLaTeX
app = Flask(__name__, template_folder="frontend")
@app.route('/')
def home():
return render_template('emailmath.html')
@app.route('/<path:path>')
def static_file(path):
return send_from_directory(app.template_folder, path)
@app.route('/api/convert', methods=['GET'])
def convert():
if request.method == 'GET':
asciimath = request.args.get('asciimath')
if asciimath is not None:
return jsonify(
latex=convertToLaTeX(asciimath),
error=False,
), 200
return jsonify(
error=True,
error_message='No AsciiMath query param found'
), 400
return jsonify(
error=True,
error_message='Only GET request allowed'
), 405
if __name__ == '__main__':
port = int(os.environ.get('PORT', 5000))
app.run(host='0.0.0.0', port=port, debug=True)