getOffVideos.py 1.9 KB

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