Bladeren bron

Merge branch 'refs/heads/master' into zhongqingkandian_0507

zhangliang 5 dagen geleden
bovenliggende
commit
fd6af13a6e
2 gewijzigde bestanden met toevoegingen van 43 en 5 verwijderingen
  1. 3 0
      application/config/config.py
  2. 40 5
      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'

+ 40 - 5
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.gpt import GPT4oMini
 from application.common.mysql.sql import Sql
 from application.common.mysql.sql import Sql
 from application.common.redis.xng_redis import xng_in_video_data
 from application.common.redis.xng_redis import xng_in_video_data
+from application.config.config import zhufuquanzi_view_api
 
 
 sys.path.append(os.getcwd())
 sys.path.append(os.getcwd())
 
 
@@ -24,6 +25,40 @@ from application.common.log import AliyunLogger
 from application.common.mysql import MysqlHelper
 from application.common.mysql import MysqlHelper
 
 
 
 
+def video_view(content_id, account_id):
+    headers = {
+        "Content-Type": "application/json"
+    }
+    payload = {
+        "content_id": str(content_id),
+        "account_id": str(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):
 class ZFQZTJLRecommend(object):
     """
     """
@@ -100,9 +135,10 @@ class ZFQZTJLRecommend(object):
         trace_id = self.platform + str(uuid.uuid1())
         trace_id = self.platform + str(uuid.uuid1())
         our_user = random.choice(self.user_list)
         our_user = random.choice(self.user_list)
         item = VideoItem()
         item = VideoItem()
+        vid = video_obj['id']
+        mid = int(video_obj['user']['mid'])
+        print(f"vid={vid},mid={mid}")
         try:
         try:
-            mid = int(video_obj['user']['mid'])
-            print(f"id:{mid}")
             user_name = video_obj['user']['nick']
             user_name = video_obj['user']['nick']
             avatar_url = video_obj['user']['hurl']
             avatar_url = video_obj['user']['hurl']
             sql = Sql()
             sql = Sql()
@@ -173,14 +209,13 @@ class ZFQZTJLRecommend(object):
             self.download_cnt += 1
             self.download_cnt += 1
             self.mq.send_msg(mq_obj)
             self.mq.send_msg(mq_obj)
             self.aliyun_log.logging(code="1002", message="成功发送至 ETL", data=mq_obj)
             self.aliyun_log.logging(code="1002", message="成功发送至 ETL", data=mq_obj)
+            video_view(vid, mid)
+            self.aliyun_log.logging(code="1010", message="触发曝光", data=mq_obj)
             if self.download_cnt >= int(
             if self.download_cnt >= int(
                     self.rule_dict.get("videos_cnt", {}).get("min", 200)
                     self.rule_dict.get("videos_cnt", {}).get("min", 200)
             ):
             ):
                 self.limit_flag = True
                 self.limit_flag = True
 
 
-
-
-
     def run(self):
     def run(self):
         self.get_recommend_list()
         self.get_recommend_list()