123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- """
- @author: luojunhui
- """
- import time
- from static.config import db_article
- from applications.functions.forward import forward_requests
- class GetOffVideos(object):
- """
- 下架视频
- """
- NEW_STRATEGY = "strategy_v2"
- def __init__(self, params, mysql_client):
- self.strategy = None
- self.params = params
- self.mysql_client = mysql_client
- self.trace_id = None
- def checkParams(self):
- """
- :return:
- """
- try:
- self.trace_id = self.params['traceId']
- self.strategy = self.params.get('strategy')
- if not self.strategy:
- self.strategy = "strategy_v1"
- 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 recall_video_id1, recall_video_id2, recall_video_id3 from {db_article}
- where trace_id = '{self.trace_id}';
- """
- recall_video_info = await self.mysql_client.async_select(sql=select_sql)
- recall_vid_tuple = recall_video_info[0]
- for vid in recall_vid_tuple:
- 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.async_insert(
- sql=update_sql,
- params=(vid, int(time.time()), 1, self.trace_id)
- )
- except Exception as e:
- print(e)
- async def deal(self):
- """
- :return:
- """
- params_error = self.checkParams()
- if params_error:
- return params_error
- else:
- if self.strategy == self.NEW_STRATEGY:
- response = await forward_requests(
- params=self.params,
- api="get_off_videos"
- )
- return response
- await self.pushVideoIntoQueue()
- response = {
- "status": "success",
- "traceId": self.trace_id
- }
- return response
|