Commit c2099d0c authored by zhanglu's avatar zhanglu

敏感词接入

parent f8ef7a8a
......@@ -60,7 +60,7 @@ class Sensitive(object):
for res in spawn.result:
data.append(cls._yidun_paraser(res, False))
for text, r in (text_list, data):
for text, r in zip(text_list, data):
result[text] = r
return result
......
......@@ -2,7 +2,7 @@ import json
from api.views.base_view import BaseView
from libs.sensitive import Sensitive
from api.utils.sensitive import Sensitive
class CreateTopicForBatch(BaseView):
......@@ -20,31 +20,44 @@ class CreateTopicForBatch(BaseView):
if not topic_list:
return self.ok()
# TODO: 过滤topic.content敏感词
topics = []
# 敏感词检测,获取可用的帖子
check_info = Sensitive.check([topic["content"] for topic in topic_list if topic.get("content")])
for topic in topic_list:
succ = check_info.get(topic.get("content")) if topic.get("content") else True
if not succ:
topics.append(topic)
if not topics:
return self.ok()
tag_names = []
for item in topic_list:
for item in topics:
tag_names.extend(item.get("tags", []))
item["user_id"] = user_id
check_info = Sensitive.check(list(filter(None, set(tag_names))))
tags = check_info.values()
check_info = Sensitive.check(tag_names)
tags = [tag_name for tag_name, succ in check_info.items() if not succ]
# 先创建标签
_tag_error, _tag_data = self.call_rpc(
"venus/community/tag/batch_create_tag_by_name",
tag_names=list(tags)
tag_names=tags
)
if _tag_error:
return self.error(_tag_error)
# 更新发帖
for item in topic_list:
item["tag_ids"] = [_tag_data.get(tag_name, 0) for tag_name in item.get("tags", [])]
for item in topics:
item["tag_ids"] = [
_tag_data[tag_name]
for tag_name in item.get("tags", []) if _tag_data.get(tag_name)
]
print(topics)
create_err, result = self.call_rpc(
"venus/community/topic/batch_create_for_inner",
topic_list=topic_list
topic_list=topics
)
if create_err:
return self.error(create_err)
......
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 to comment