123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- """
- @author: luojunhui
- """
- import json
- import time
- class GetOffVideos(object):
- """
- 下架视频
- """
- def __init__(self, params, mysql_client, config):
- self.params = params
- self.mysql_client = mysql_client
- self.articles_video = config.articleVideos
- self.trace_id = None
- def checkParams(self):
- """
- :return:
- """
- try:
- self.trace_id = self.params['traceId']
- return None
- except Exception as e:
- response = {
- "error": "params error",
- "info": str(e),
- "data": self.params
- }
- return response
- async def pushVideoIntoQueue(self):
- """
- 将视频id记录到待下架表中
- :return:
- """
- select_sql = f"""
- select response from {self.articles_video} where trace_id = '{self.trace_id}';
- """
- result = await self.mysql_client.asyncSelect(sql=select_sql)
- if result:
- video_list = json.loads(result[0][0])
- for video in video_list:
- video_id = video['videoId']
- try:
- update_sql = f"""
- INSERT INTO get_off_videos
- (video_id, publish_time, video_status, trace_id)
- values
- (%s, %s, %s, %s);
- """
- await self.mysql_client.asyncInsert(
- sql=update_sql,
- params=(video_id, int(time.time()), 1, self.trace_id)
- )
- except Exception as e:
- print(e)
- else:
- print("该 trace_id不存在")
- async def deal(self):
- """
- :return:
- """
- params_error = self.checkParams()
- if params_error:
- return params_error
- else:
- await self.pushVideoIntoQueue()
- response = {
- "status": "success",
- "traceId": self.trace_id
- }
- return response
|