get_off_videos.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. """
  2. @author: luojunhui
  3. """
  4. import json
  5. import time
  6. class GetOffVideos(object):
  7. """
  8. 下架视频
  9. """
  10. def __init__(self, params, mysql_client, config):
  11. self.params = params
  12. self.mysql_client = mysql_client
  13. self.articles_video = config.articleVideos
  14. self.trace_id = None
  15. def checkParams(self):
  16. """
  17. :return:
  18. """
  19. try:
  20. self.trace_id = self.params['traceId']
  21. return None
  22. except Exception as e:
  23. response = {
  24. "error": "params error",
  25. "info": str(e),
  26. "data": self.params
  27. }
  28. return response
  29. async def pushVideoIntoQueue(self):
  30. """
  31. 将视频id记录到待下架表中
  32. :return:
  33. """
  34. select_sql = f"""
  35. select response from {self.articles_video} where trace_id = '{self.trace_id}';
  36. """
  37. result = await self.mysql_client.asyncSelect(sql=select_sql)
  38. if result:
  39. video_list = json.loads(result[0][0])
  40. for video in video_list:
  41. video_id = video['videoId']
  42. try:
  43. update_sql = f"""
  44. INSERT INTO get_off_videos
  45. (video_id, publish_time, video_status, trace_id)
  46. values
  47. (%s, %s, %s, %s);
  48. """
  49. await self.mysql_client.asyncInsert(
  50. sql=update_sql,
  51. params=(video_id, int(time.time()), 1, self.trace_id)
  52. )
  53. except Exception as e:
  54. print(e)
  55. else:
  56. print("该 trace_id不存在")
  57. async def deal(self):
  58. """
  59. :return:
  60. """
  61. params_error = self.checkParams()
  62. if params_error:
  63. return params_error
  64. else:
  65. await self.pushVideoIntoQueue()
  66. response = {
  67. "status": "success",
  68. "traceId": self.trace_id
  69. }
  70. return response