浏览代码

祝福圈子推荐流 增加曝光

supeng 1 天之前
父节点
当前提交
4b04e8df06
共有 2 个文件被更改,包括 40 次插入3 次删除
  1. 3 0
      application/config/config.py
  2. 37 3
      spider/crawler_online/zhufuquanzituijianliu.py

+ 3 - 0
application/config/config.py

@@ -0,0 +1,3 @@
+# api 配置
+crawler_api_domain = 'http://8.217.192.46:8889'
+zhufuquanzi_view_api = crawler_api_domain + '/crawler/zhu_fu_quan_zi/detail_exposure'

+ 37 - 3
spider/crawler_online/zhufuquanzituijianliu.py

@@ -14,6 +14,7 @@ from application.common.feishu.feishu_utils import FeishuUtils
 from application.common.gpt import GPT4oMini
 from application.common.mysql.sql import Sql
 from application.common.redis.xng_redis import xng_in_video_data
+from application.config.config import zhufuquanzi_view_api
 
 sys.path.append(os.getcwd())
 
@@ -24,6 +25,40 @@ from application.common.log import AliyunLogger
 from application.common.mysql import MysqlHelper
 
 
+def video_view(content_id, account_id):
+    headers = {
+        "Content-Type": "application/json"
+    }
+    payload = {
+        "content_id": content_id,
+        "account_id": account_id
+    }
+    try:
+        # 发送 POST 请求
+        response = requests.post(
+            zhufuquanzi_view_api,
+            headers=headers,
+            json=payload  # 自动将字典转换为 JSON
+        )
+        # 检查 HTTP 状态码
+        if response.status_code == 200:
+            # 解析 JSON 响应
+            result = response.json()
+            # 提取关键字段
+            code = result.get("code")
+            msg = result.get("msg")
+            # 业务逻辑处理(示例)
+            if code == 0:
+                print("请求成功")
+            else:
+                print(f"请求失败,错误码: {code}, 消息: {msg}")
+        else:
+            print(f"HTTP 请求失败,状态码: {response.status_code}")
+    except requests.exceptions.RequestException as e:
+        print(f"请求异常: {e}")
+    except json.JSONDecodeError:
+        print("响应不是有效的 JSON 格式")
+
 
 class ZFQZTJLRecommend(object):
     """
@@ -173,14 +208,13 @@ class ZFQZTJLRecommend(object):
             self.download_cnt += 1
             self.mq.send_msg(mq_obj)
             self.aliyun_log.logging(code="1002", message="成功发送至 ETL", data=mq_obj)
+            video_view(video_obj["id"], video_obj['user']['mid'])
+            self.aliyun_log.logging(code="1010", message="触发曝光", data=mq_obj)
             if self.download_cnt >= int(
                     self.rule_dict.get("videos_cnt", {}).get("min", 200)
             ):
                 self.limit_flag = True
 
-
-
-
     def run(self):
         self.get_recommend_list()