박선진

API 개발

from flask import Flask, request
from flask_restplus import Resource, Api, fields
import process
import base64
if __name__ == '__main__':
p = process.Process()
app = Flask(__name__, static_url_path='/static')
api = Api(app, version='1.0', title='FlaskLocal', description='FlaskLocal')
# image to base64 encoding
# you have to set 'encoded_image' to frame code
with open("./known_images/obama.jpg", "rb") as img_file:
encoded_obama_image = base64.b64encode(img_file.read())
ns_node = api.namespace('node', description='node API')
node_response = ns_node.model("test_response",{
"unknown_person": fields.Boolean,
"fire_broken" : fields.Boolean
})
with open("./test_images/Fire.jpg", "rb") as img_file:
encoded_fire_image = base64.b64encode(img_file.read())
node_request = ns_node.model('test_request', {
'data': fields.String
})
with open("./test_images/unknown.jpg", "rb") as img_file:
encoded_unknown_image = base64.b64encode(img_file.read())
#앱빌더를 통해 새 게시물 & 댓글 알림 수신
@ns_node.route('/process')
class test(Resource):
@ns_node.doc('post')
@ns_node.expect(node_request)
#@ns_node.marshal_with(node_response)
def post(self):
print(api)
print(api.payload)
#res = node.ProcessImage(api.payload)
#return res
p.ProcessImage(encoded_obama_image)
p.ProcessImage(encoded_fire_image)
p.ProcessImage(encoded_unknown_image)
\ No newline at end of file
@app.route('/process', methods=['POST'])
def post():
#print(request.form)
res = node.ProcessImage(request.form)
return res
if __name__ == '__main__':
node = process.Process()
app.run(host='0.0.0.0', port=80, threaded=False)
......