Browse Source

add notify backend updateFallBackVideoList

liqian 2 years ago
parent
commit
82d1c683b5
3 changed files with 24 additions and 2 deletions
  1. 8 0
      config.py
  2. 15 2
      special_mid_videos_update.py
  3. 1 0
      utils.py

+ 8 - 0
config.py

@@ -368,6 +368,8 @@ class DevelopmentConfig(BaseConfig):
     TOP_VIDEO_LIST_URL = 'http://videotest-internal.yishihui.com/longvideoapi/openapi/recommend/topVideoList'
     # 获取首页兜底视频json接口地址
     BOTTOM_JSON_URL = 'http://videotest-internal.yishihui.com/longvideoapi/openapi/video/distribute/structure/video/list'
+    # 通知后端更新兜底视频接口地址
+    NOTIFY_BACKEND_updateFallBackVideoList_URL = 'http://videotest-internal.yishihui.com/longvideoapi/openapi/recommend/updateFallBackVideoList'
 
     # logs 上传oss 目标Bucket指定目录
     OSS_FOLDER_LOGS = 'rov-offline/dev/logs/'
@@ -444,6 +446,8 @@ class TestConfig(BaseConfig):
     TOP_VIDEO_LIST_URL = 'http://videotest-internal.yishihui.com/longvideoapi/openapi/recommend/topVideoList'
     # 获取首页兜底视频json接口地址
     BOTTOM_JSON_URL = 'http://videotest-internal.yishihui.com/longvideoapi/openapi/video/distribute/structure/video/list'
+    # 通知后端更新兜底视频接口地址
+    NOTIFY_BACKEND_updateFallBackVideoList_URL = 'http://videotest-internal.yishihui.com/longvideoapi/openapi/recommend/updateFallBackVideoList'
 
     # logs 上传oss 目标Bucket指定目录
     OSS_FOLDER_LOGS = 'rov-offline/test/logs/'
@@ -520,6 +524,8 @@ class PreProductionConfig(BaseConfig):
     TOP_VIDEO_LIST_URL = 'http://speedpre.wx.com/longvideoapi/openapi/recommend/topVideoList'
     # 获取首页兜底视频json接口地址
     BOTTOM_JSON_URL = 'http://speedpre.wx.com/longvideoapi/openapi/video/distribute/structure/video/list'
+    # 通知后端更新兜底视频接口地址
+    NOTIFY_BACKEND_updateFallBackVideoList_URL = 'http://videopre-internal.piaoquantv.com/longvideoapi/openapi/recommend/updateFallBackVideoList'
 
     # logs 上传oss 目标Bucket指定目录
     OSS_FOLDER_LOGS = 'rov-offline/pre/logs/'
@@ -596,6 +602,8 @@ class ProductionConfig(BaseConfig):
     TOP_VIDEO_LIST_URL = 'http://recommend-common-internal.piaoquantv.com/longvideoapi/openapi/recommend/topVideoList'
     # 获取首页兜底视频json接口地址
     BOTTOM_JSON_URL = 'http://recommend-common-internal.piaoquantv.com/longvideoapi/openapi/video/distribute/structure/video/list'
+    # 通知后端更新兜底视频接口地址
+    NOTIFY_BACKEND_updateFallBackVideoList_URL = 'http://recommend-common-internal.piaoquantv.com/longvideoapi/openapi/recommend/updateFallBackVideoList'
 
     # logs 上传oss 目标Bucket指定目录
     OSS_FOLDER_LOGS = 'rov-offline/pro/logs/'

+ 15 - 2
special_mid_videos_update.py

@@ -9,7 +9,7 @@ from get_data import get_data_from_odps
 from db_helper import RedisHelper, MysqlHelper
 from config import set_config
 from log import Log
-from utils import filter_video_status_with_applet_rec
+from utils import request_post
 
 config_, env = set_config()
 log_ = Log()
@@ -46,8 +46,12 @@ def get_special_videos(now_date, project, table):
     video_id_list = [record['videoid'] for record in records]
     # 排序合并,随机给定分数
     final_result = {}
+    json_data = []
     for video_id in video_id_list:
-        final_result[int(video_id)] = random.uniform(0, 100)
+        score = random.uniform(0, 100)
+        final_result[int(video_id)] = score
+        json_data.append({'videoId': video_id, 'rovScore': score})
+
     # 写入对应的redis
     key_name = \
         f"{config_.KEY_NAME_PREFIX_SPECIAL_VIDEOS}{datetime.datetime.strftime(now_date, '%Y%m%d')}"
@@ -55,6 +59,15 @@ def get_special_videos(now_date, project, table):
         redis_helper = RedisHelper()
         redis_helper.add_data_with_zset(key_name=key_name, data=final_result, expire_time=2 * 24 * 3600)
 
+    # 通知后端更新兜底视频数据
+    log_.info('json_data count = {}'.format(len(json_data)))
+    result = request_post(request_url=config_.NOTIFY_BACKEND_updateFallBackVideoList_URL,
+                          request_data={'videos': json_data})
+    if result['code'] == 0:
+        log_.info('notify backend updateFallBackVideoList success!')
+    else:
+        log_.error('notify backend updateFallBackVideoList fail!')
+
 
 def h_timer_check():
     project = config_.SPECIAL_MID_VIDEOS_PROJECT.get('videos')

+ 1 - 0
utils.py

@@ -113,6 +113,7 @@ def request_post(request_url, request_data=None):
             res_data = json.loads(response.text)
             return res_data
         else:
+            log_.info(f"response.status_code: {response.status_code}")
             return None
     except Exception as e:
         log_.error('url: {}, exception: {}, traceback: {}'.format(request_url, e, traceback.format_exc()))