-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathserver.py
47 lines (34 loc) · 1.04 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date : 2018-06-27 16:09:53
# @Author : Artio ([email protected])
# @Link : http://github.com/luopeixiong
# @Version : $Id$
import os
from core import TycTTF
from flask import Flask, request, jsonify
def run(font_key, word):
obj = TycTTF(font_key)
return obj.run(word)
def create_app():
app = Flask(__name__)
return app
def init_app(app:Flask):
@app.route('/api',methods=['GET', 'POST'])
def api():
if request.method == 'GET':
font_key = request.args['font_key']
word = request.args['word']
return jsonify({'result': run(font_key, word)})
elif request.method == 'POST':
print(request.form)
font_key = request.form.get('font_key')
word = request.form.get('word')
return jsonify({'result': run(font_key, word)})
return 'error',404
def main():
app = create_app()
init_app(app)
app.run(host='0.0.0.0',port=5000,debug=True)
if __name__ == '__main__':
main()