search_schedule.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. return None
  48. # xigua_result = xigua_search(title)
  49. # if xigua_result:
  50. # return {
  51. # "platform": "xg_search",
  52. # "result": xigua_result[0]
  53. # }
  54. # else:
  55. # logging(
  56. # code="7001",
  57. # info="通过西瓜搜索失败---{}".format(title),
  58. # trace_id=trace_id
  59. # )
  60. # return None
  61. else:
  62. logging(
  63. code="7000",
  64. info="标题--{}--kimi 挖掘数据失败".format(title),
  65. trace_id=trace_id
  66. )
  67. return None
  68. def search_videos(video_path, title, trace_id, gh_id):
  69. """
  70. search and send msg to ETL
  71. :param gh_id:
  72. :param video_path:
  73. :param title:
  74. :param trace_id:
  75. :return:
  76. """
  77. recall_obj = recall_search_video(video_path, title, trace_id)
  78. if recall_obj:
  79. platform = recall_obj["platform"]
  80. recall_video = recall_obj["result"]
  81. if recall_video:
  82. logging(
  83. code="7002",
  84. info="视频搜索成功, 搜索平台为--{}".format(platform),
  85. trace_id=trace_id,
  86. data=recall_video
  87. )
  88. video_mq_sender(
  89. video_obj=recall_video,
  90. user=gh_id_dict.get(gh_id),
  91. trace_id=trace_id,
  92. platform=platform
  93. )
  94. else:
  95. logging(
  96. code="7003",
  97. info="视频搜索失败",
  98. trace_id=trace_id
  99. )