getOffVideos.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. """
  2. @author: luojunhui
  3. """
  4. import time
  5. from static.config import db_article
  6. from applications.functions.forward import forward_requests
  7. class GetOffVideos(object):
  8. """
  9. 下架视频
  10. """
  11. NEW_STRATEGY = "strategy_v2"
  12. def __init__(self, params, mysql_client):
  13. self.strategy = None
  14. self.params = params
  15. self.mysql_client = mysql_client
  16. self.trace_id = None
  17. def checkParams(self):
  18. """
  19. :return:
  20. """
  21. try:
  22. self.trace_id = self.params['traceId']
  23. self.strategy = self.params.get('strategy')
  24. if not self.strategy:
  25. self.strategy = "strategy_v1"
  26. return None
  27. except Exception as e:
  28. response = {
  29. "error": "params error",
  30. "info": str(e),
  31. "data": self.params
  32. }
  33. return response
  34. async def pushVideoIntoQueue(self):
  35. """
  36. 将视频id记录到待下架表中
  37. :return:
  38. """
  39. select_sql = f"""
  40. select recall_video_id1, recall_video_id2, recall_video_id3 from {db_article}
  41. where trace_id = '{self.trace_id}';
  42. """
  43. recall_video_info = await self.mysql_client.async_select(sql=select_sql)
  44. recall_vid_tuple = recall_video_info[0]
  45. for vid in recall_vid_tuple:
  46. try:
  47. update_sql = f"""
  48. INSERT INTO get_off_videos
  49. (video_id, publish_time, video_status, trace_id)
  50. values
  51. (%s, %s, %s, %s);
  52. """
  53. await self.mysql_client.async_insert(
  54. sql=update_sql,
  55. params=(vid, int(time.time()), 1, self.trace_id)
  56. )
  57. except Exception as e:
  58. print(e)
  59. async def deal(self):
  60. """
  61. :return:
  62. """
  63. params_error = self.checkParams()
  64. if params_error:
  65. return params_error
  66. else:
  67. if self.strategy == self.NEW_STRATEGY:
  68. response = await forward_requests(
  69. params=self.params,
  70. api="get_off_videos"
  71. )
  72. return response
  73. await self.pushVideoIntoQueue()
  74. response = {
  75. "status": "success",
  76. "traceId": self.trace_id
  77. }
  78. return response