박선진

API 개발

1 +from flask import Flask, request
2 +from flask_restplus import Resource, Api, fields
3 +
1 import process 4 import process
2 -import base64
3 5
4 -if __name__ == '__main__': 6 +app = Flask(__name__, static_url_path='/static')
5 - p = process.Process() 7 +api = Api(app, version='1.0', title='FlaskLocal', description='FlaskLocal')
8 +
9 +ns_node = api.namespace('node', description='node API')
10 +node_response = ns_node.model("test_response",{
11 + "unknown_person": fields.Boolean,
12 + "fire_broken" : fields.Boolean
13 +})
6 14
7 - # image to base64 encoding 15 +node_request = ns_node.model('test_request', {
8 - # you have to set 'encoded_image' to frame code 16 + 'data': fields.String
9 - with open("./known_images/obama.jpg", "rb") as img_file: 17 +})
10 - encoded_obama_image = base64.b64encode(img_file.read())
11 18
12 - with open("./test_images/Fire.jpg", "rb") as img_file: 19 +#앱빌더를 통해 새 게시물 & 댓글 알림 수신
13 - encoded_fire_image = base64.b64encode(img_file.read()) 20 +@ns_node.route('/process')
21 +class test(Resource):
22 + @ns_node.doc('post')
23 + @ns_node.expect(node_request)
24 + #@ns_node.marshal_with(node_response)
25 + def post(self):
26 + print(api)
27 + print(api.payload)
28 + #res = node.ProcessImage(api.payload)
29 + #return res
14 30
15 - with open("./test_images/unknown.jpg", "rb") as img_file:
16 - encoded_unknown_image = base64.b64encode(img_file.read())
17 -
18 - p.ProcessImage(encoded_obama_image)
19 - p.ProcessImage(encoded_fire_image)
20 - p.ProcessImage(encoded_unknown_image)
...\ No newline at end of file ...\ No newline at end of file
31 +@app.route('/process', methods=['POST'])
32 +def post():
33 + #print(request.form)
34 + res = node.ProcessImage(request.form)
35 + return res
36 +
37 +if __name__ == '__main__':
38 + node = process.Process()
39 + app.run(host='0.0.0.0', port=80, threaded=False)
......