Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
lichenggang
/
bom_identify
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
14cd7fad
authored
Nov 03, 2020
by
lichenggang
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
对外服务优化
parent
3e8fa684
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
10 deletions
http_server.py
utils/status.py
http_server.py
View file @
14cd7fad
...
...
@@ -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
)
...
...
utils/status.py
View file @
14cd7fad
...
...
@@ -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
]}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment