123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- """
- @author: luojunhui
- """
- import requests
- from applications.functions import title_sim_v2_by_list
- from applications.functions import get_article_title_url_list, get_article_titles
- class LongArticlesPipeline(object):
- """
- Long articles Pipeline
- """
- @classmethod
- def history_exists(cls, title, account_nickname, plan_name):
- """
- 判断是否存储
- :param plan_name:
- :param title:
- :param account_nickname:
- :return:
- """
- if "【1】" in plan_name or "【2】" in plan_name:
- index_list = [1, 2]
- else:
- index_list = [1, 2, 3, 4, 5, 6, 7, 8]
- account_title_list = get_article_titles(
- account_nickname,
- index_list=index_list
- )
- print(account_title_list)
- sim_res = title_sim_v2_by_list(title, account_title_list)
- if sim_res:
- return True
- return False
- @classmethod
- def article_safe(cls, title):
- """
- 判断文章是否安全
- """
- url = "http://192.168.100.31:8177/sensitive/is_sensitive"
- body = {
- "text": title
- }
- response = requests.post(
- url=url,
- json=body,
- headers={"Content-Type": "application/json"}
- )
- return response.json()['is_sensitive']
- @classmethod
- def article_bad(cls, title, account_nickname):
- """
- 判断该文章是否为劣质文章
- :param title:
- :param account_nickname:
- :return:
- """
- url = "http://192.168.100.31:8176/bad/is_bad"
- headers = {
- "accept": "application/json",
- "Content-Type": "application/json"
- }
- body = {
- "account_nickname": account_nickname,
- "title": title
- }
- response = requests.request(
- "POST",
- url=url,
- headers=headers,
- json=body
- )
- return response.json()['is_bad']
- @classmethod
- def deal(cls, article_obj, account_name):
- """
- :param account_name:
- :param article_obj:
- :return:
- """
- article_bad_flag = cls.article_bad(
- title=article_obj['title'],
- account_nickname=account_name
- )
- if article_bad_flag:
- response = {
- "filterReason": "历史表现差的文章",
- "status": True
- }
- return response
- else:
- history_exists_flag = cls.history_exists(
- title=article_obj['title'],
- account_nickname=account_name,
- plan_name=article_obj['producePlanName']
- )
- if history_exists_flag:
- response = {
- "filterReason": "历史已发布文章",
- "status": True
- }
- return response
- else:
- safe_flag = cls.article_safe(title=article_obj['title'])
- if safe_flag:
- response = {
- "filterReason": "安全违规",
- "status": True
- }
- return response
- else:
- return False
|