pipeline.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. """
  2. @author: luojunhui
  3. """
  4. import requests
  5. from applications.functions import title_sim_v2_by_list
  6. from applications.functions import get_article_title_url_list, get_article_titles
  7. class LongArticlesPipeline(object):
  8. """
  9. Long articles Pipeline
  10. """
  11. @classmethod
  12. def history_exists(cls, title, account_nickname, plan_name):
  13. """
  14. 判断是否存储
  15. :param plan_name:
  16. :param title:
  17. :param account_nickname:
  18. :return:
  19. """
  20. if "【1】" in plan_name or "【2】" in plan_name:
  21. index_list = [1, 2]
  22. else:
  23. index_list = [1, 2, 3, 4, 5, 6, 7, 8]
  24. account_title_list = get_article_titles(
  25. account_nickname,
  26. index_list=index_list
  27. )
  28. print(account_title_list)
  29. sim_res = title_sim_v2_by_list(title, account_title_list)
  30. if sim_res:
  31. return True
  32. return False
  33. @classmethod
  34. def article_safe(cls, title):
  35. """
  36. 判断文章是否安全
  37. """
  38. url = "http://192.168.100.31:8177/sensitive/is_sensitive"
  39. body = {
  40. "text": title
  41. }
  42. response = requests.post(
  43. url=url,
  44. json=body,
  45. headers={"Content-Type": "application/json"}
  46. )
  47. return response.json()['is_sensitive']
  48. @classmethod
  49. def article_bad(cls, title, account_nickname):
  50. """
  51. 判断该文章是否为劣质文章
  52. :param title:
  53. :param account_nickname:
  54. :return:
  55. """
  56. url = "http://192.168.100.31:8176/bad/is_bad"
  57. headers = {
  58. "accept": "application/json",
  59. "Content-Type": "application/json"
  60. }
  61. body = {
  62. "account_nickname": account_nickname,
  63. "title": title
  64. }
  65. response = requests.request(
  66. "POST",
  67. url=url,
  68. headers=headers,
  69. json=body
  70. )
  71. return response.json()['is_bad']
  72. @classmethod
  73. def deal(cls, article_obj, account_name):
  74. """
  75. :param account_name:
  76. :param article_obj:
  77. :return:
  78. """
  79. article_bad_flag = cls.article_bad(
  80. title=article_obj['title'],
  81. account_nickname=account_name
  82. )
  83. if article_bad_flag:
  84. response = {
  85. "filterReason": "历史表现差的文章",
  86. "status": True
  87. }
  88. return response
  89. else:
  90. history_exists_flag = cls.history_exists(
  91. title=article_obj['title'],
  92. account_nickname=account_name,
  93. plan_name=article_obj['producePlanName']
  94. )
  95. if history_exists_flag:
  96. response = {
  97. "filterReason": "历史已发布文章",
  98. "status": True
  99. }
  100. return response
  101. else:
  102. safe_flag = cls.article_safe(title=article_obj['title'])
  103. if safe_flag:
  104. response = {
  105. "filterReason": "安全违规",
  106. "status": True
  107. }
  108. return response
  109. else:
  110. return False