weixin_search.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. """
  2. @author: luojunhui
  3. """
  4. import json
  5. import requests
  6. from applications.functions.common import MySQLServer
  7. def wx_search(keys):
  8. """
  9. WeChat search
  10. :param keys:
  11. :return:
  12. """
  13. sensitive_words = MySQLServer().select_sensitive_words()
  14. def sensitive_flag(s_words, ori_title):
  15. """
  16. :param ori_title:
  17. :param s_words:
  18. :return:
  19. """
  20. for word in s_words:
  21. if word in ori_title:
  22. return False
  23. return True
  24. url = "http://8.217.190.241:8888/crawler/wei_xin/keyword"
  25. payload = json.dumps({
  26. "keyword": keys,
  27. "cursor": "0",
  28. "content_type": "video"
  29. })
  30. headers = {
  31. 'Content-Type': 'application/json'
  32. }
  33. response = requests.request("POST", url, headers=headers, data=payload).json()
  34. if response['msg'] == '未知错误':
  35. return []
  36. else:
  37. L = []
  38. if response['data']:
  39. video_list = response['data']['data']
  40. for video in video_list:
  41. try:
  42. video_info = video['items'][0]
  43. title = video_info['title']
  44. duration_str = video_info['duration']
  45. dr = int(duration_str.split(":")[0].strip()) + int(duration_str.split(":")[1].strip())
  46. if sensitive_flag(sensitive_words, title) and dr <= 300:
  47. L.append(video_info)
  48. else:
  49. continue
  50. except:
  51. pass
  52. return L