Commit 14cd7fad by lichenggang

对外服务优化

parent 3e8fa684
Showing with 15 additions and 10 deletions
......@@ -18,13 +18,17 @@ class BaseHandler(tornado.web.RequestHandler):
class KwHandler(BaseHandler):
async def get(self):
target = unquote(self.get_argument('keyword'))
predict_type = unquote(self.get_argument('type', 'all'))
bom_log.info(f'http收到识别关键词: {target}, 预测类型为{predict_type}')
code, res = self.predictorfac.predict(target, predict_type)
target = unquote(self.get_argument('keyword', ''))
if not target:
code = '100001'
res = code2msg(code)
else:
predict_type = unquote(self.get_argument('type', 'all'))
bom_log.info(f'http收到识别关键词: {target}, 预测类型为{predict_type}')
code, res = self.predictorfac.predict(target, predict_type)
if code != 1:
res = code2msg(code)
bom_log.error(f'http关键词识别报错: ' + res['message'])
bom_log.error(f'http关键词识别报错: ' + res['err_message'])
else:
res['status'] = code
self.write(res)
......@@ -32,12 +36,12 @@ class KwHandler(BaseHandler):
async def post(self):
target = self.request.body
list_data = json.loads(self.request.body)
predict_type = unquote(self.get_argument('type', 'all'))
predict_type = unquote(self.get_argument('type', 'param'))
bom_log.info(f'http收到识别关键词列表: {target}, 预测类型为{predict_type}')
code, res = self.predictorfac.predict(list_data, predict_type)
if code != 1:
res = code2msg(code)
bom_log.error(f'http关键词批量识别报错: ' + res['message'])
bom_log.error(f'http关键词批量识别报错: ' + res['err_message'])
else:
res['status'] = code
self.write(res)
......@@ -49,10 +53,11 @@ class DictHandler(BaseHandler):
dic_data = json.loads(self.request.body)
code, res = self.predictorfac.predict(dic_data)
except json.decoder.JSONDecodeError:
code, res = self.predictorfac.predict(self.request.body)
code = '100001'
res = code2msg(code)
if code != 1:
res = code2msg(code)
bom_log.error(f'http识别报错: ' + res['message'])
bom_log.error(f'http识别报错: ' + res['err_message'])
else:
res['status'] = code
self.write(res)
......
......@@ -6,7 +6,7 @@ import inspect
def code2msg(code):
if code in StatusCode.StatusDict:
return {"status": code, "message": StatusCode.StatusDict[code][1]}
return {"status": code, "err_message": StatusCode.StatusDict[code][1]}
else:
return {"status": "0", "message": StatusCode.StatusDict["0"][1]}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment