search_schedule.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. """
  2. @author: luojunhui
  3. 调用接口在微信内搜索视频
  4. """
  5. import json
  6. from applications.search import *
  7. from applications.static.config import gh_id_dict
  8. from applications.functions.log import logging
  9. from applications.functions.video_item import video_mq_sender
  10. def recall_search_video(video_path, title, trace_id):
  11. """
  12. search and send msg to ETL
  13. :param trace_id:
  14. :param title: 视频标题
  15. :param video_path: 视频路径
  16. :return:
  17. """
  18. with open(video_path, encoding='utf-8') as f:
  19. my_obj = json.loads(f.read())
  20. if my_obj:
  21. wx_result = wx_search(keys=title)
  22. if wx_result:
  23. return {
  24. "platform": "wx_search",
  25. "result": wx_result[0]
  26. }
  27. else:
  28. logging(
  29. code="7001",
  30. info="通过微信搜索失败---{}".format(title),
  31. trace_id=trace_id
  32. )
  33. # 微信搜不到的话,采用好看视频搜索
  34. baidu_result = hksp_search(key=title)
  35. if baidu_result:
  36. return {
  37. "platform": "baidu_search",
  38. "result": baidu_result[0]
  39. }
  40. else:
  41. # 若好看视频未搜到,则采用西瓜搜索
  42. logging(
  43. code="7001",
  44. info="通过baidu搜索失败---{}".format(title),
  45. trace_id=trace_id
  46. )
  47. xigua_result = xigua_search(title)
  48. if xigua_result:
  49. return {
  50. "platform": "xg_search",
  51. "result": xigua_result[0]
  52. }
  53. else:
  54. logging(
  55. code="7001",
  56. info="通过西瓜搜索失败---{}".format(title),
  57. trace_id=trace_id
  58. )
  59. return None
  60. else:
  61. logging(
  62. code="7000",
  63. info="标题--{}--kimi 挖掘数据失败".format(title),
  64. trace_id=trace_id
  65. )
  66. return None
  67. def search_videos(video_path, title, trace_id, gh_id):
  68. """
  69. search and send msg to ETL
  70. :param gh_id:
  71. :param video_path:
  72. :param title:
  73. :param trace_id:
  74. :return:
  75. """
  76. recall_obj = recall_search_video(video_path, title, trace_id)
  77. platform = recall_obj["platform"]
  78. recall_video = recall_obj["result"]
  79. if recall_video:
  80. logging(
  81. code="7002",
  82. info="视频搜索成功, 搜索平台为--{}".format(platform),
  83. trace_id=trace_id,
  84. data=recall_video
  85. )
  86. video_mq_sender(
  87. video_obj=recall_video,
  88. user=gh_id_dict.get(gh_id),
  89. trace_id=trace_id,
  90. platform=platform
  91. )
  92. else:
  93. logging(
  94. code="7003",
  95. info="视频搜索失败",
  96. trace_id=trace_id
  97. )