Commit c2099d0c authored by zhanglu's avatar zhanglu

敏感词接入

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