Forráskód Böngészése

磁力聚星内容相似达人推荐

zhangyong 10 hónapja
szülő
commit
54a3ed3755
4 módosított fájl, 193 hozzáadás és 22 törlés
  1. 23 7
      common/sql_help.py
  2. 121 12
      data_channel/cljx_nrxs.py
  3. 25 0
      data_channel/ks_nrxs.py
  4. 24 3
      ks_qpl_main.py

+ 23 - 7
common/sql_help.py

@@ -127,13 +127,29 @@ class sqlCollect():
     获取相似溯源基础账号
     """
     @classmethod
-    def get_machine_making_reflux(cls, channel):
-        sql = """
-                        SELECT user
-                        FROM machine_making_reflux
-                        WHERE channel = %s and status = 0
-                    """
-        data = MysqlHelper.get_values(sql, (channel))
+    def get_machine_making_reflux(cls, channel, channel1):
+        sql = """SELECT user FROM machine_making_reflux WHERE (channel = %s or channel = %s) and status = 0"""
+        data = MysqlHelper.get_values(sql, (channel, channel1))
         if len(data) == 0 or data == ():
             return None
         return data
+
+    """
+    修改相似溯源基础账号状态
+    """
+    @classmethod
+    def update_machine_making_reflux(cls, user_id):
+        sql = f"""UPDATE machine_making_reflux set status = 1 where user = '{user_id}'"""
+        res = MysqlHelper.update_values(
+            sql=sql
+        )
+        return res
+
+    """插入符合规则的用户主页"""
+    @classmethod
+    def insert_user_data(cls, uid, name, account_id, channel, status):
+        insert_sql = f"""INSERT INTO machine_making_traceability (old_account_id, name, new_account_id, channel, status) values ("{uid}", "{name}","{account_id}","{channel}", {status})"""
+        MysqlHelper.update_values(
+            sql=insert_sql
+        )
+

+ 121 - 12
data_channel/cljx_nrxs.py

@@ -1,3 +1,4 @@
+import random
 import time
 
 import requests
@@ -8,7 +9,9 @@ from common.sql_help import sqlCollect
 
 
 class CLJX:
-
+    """
+    磁力聚星-内容相似
+    """
     @classmethod
     def get_ks_account_id(cls, user_id):
         url = "http://8.217.190.241:8888/crawler/kuai_shou/account_info"
@@ -37,14 +40,82 @@ class CLJX:
                               "【快手 Token 使用提示 】")
             return None
 
+    """
+    获取用户主页id
+    """
+    @classmethod
+    def get_cljx_user(cls, user_id):
+        url = "https://k.kuaishou.com/rest/web/star/starProfile"
+
+        payload = json.dumps({
+            "starId": user_id,
+            "starType": 1
+        })
+        headers = {
+            'Accept': 'application/json',
+            'Accept-Language': 'zh-CN,zh;q=0.9',
+            'Content-Type': 'application/json',
+            'Cookie': 'did=web_9c6a04a4004fdb7c95a658a56ed275b6; apdid=328ac94f-4040-41fe-a038-b60140291aca99fb22e9862c74736f53d57b666ee53b:1719580529:1; language=zh-CN; ud=2205012540; app_id=ks686235996059836592; expire_time=1800; userId=2574854626; didv=1723085291918; access_token=ChFvYXV0aC5hY2Nlc3NUb2tlbhIwxAynR0a25DAwASSZyFW_SXVKItA9eLgPL9QE3uhjbXbxOZKZHOd2ZN5XA28WC_yhGhI2htRBeNJJsoU2p999XVFiCx8iINiMEx_garq3ocgmbowCwQEHrGSU3DHRVgcP256vtgogKAUwAQ; nc_user_id=CiVhZC5ub3RpZnkuY2VudGVyLm9hdXRoLnVzZXIuaWQuc2VjcmV0EiD3Ti1DDwjCt6yg6dWPwJ0ORdOr8FJXzTZs1oramKY6lBoS2NP9Dh0WHkEo1U4//HlOPvrHIiCyOJ7XywzTEB831l48hsXwEUPoCfOWlivj2ImMavMg2SgFMAE=; kuaishou.ad.social_st=ChVrdWFpc2hvdS5hZC5zb2NpYWwuc3QSoAGYIByd-51FdrhEkJ0gKeGxIfc9ENhrDEzFEoCMlMJJqK3NkzgxivGEt2nrsjO9nES9Kk7_bdr2-ILnlEiCdTk3VV3tjQNJ0AIdAco58wYxSgFGoiTzm_70s9K7pNo_Xtu_Td715BLcoJWSi-8kr8c51_lK1bf5WudF6Mu0_ux3l7j3xMULUfPlgQWyOsoGLmZZc-D2nJ1y-b1mQpSDOR75GhI9XS-Z7CpEB6YeaJVDlC5cHwQiIAJYR4iZ-BOCyoxQsdkV1qXAI5Pt8XUFJaqlKkkDVDt3KAUwAQ; kuaishou.ad.social_ph=2bedb2aeb05a5b4bb0e8103a2b4e68029ecc; did=web_9c6a04a4004fdb7c95a658a56ed275b6; didv=1711522726000',
+            'Origin': 'https://k.kuaishou.com',
+            'Pragma': 'no-cache',
+            'Referer': 'https://k.kuaishou.com/',
+            'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36'
+        }
+
+        response = requests.request("POST", url, headers=headers, data=payload)
+        time.sleep(1)
+        response = response.json()
+        result = response['result']
+        if result == 1:
+            profile_id = response["starProfile"]["profileId"]
+            return profile_id
+        else:
+            print("提示")
+            Feishu.finish_bot("Token 过期,请及时更换",
+                              "https://open.feishu.cn/open-apis/bot/v2/hook/575ca6a1-84b4-4a2f-983b-1d178e7b16eb",
+                              "【磁力聚星提示】")
+
+    @classmethod
+    def get_ks_list(cls, url_id):
+        url = "http://8.217.190.241:8888/crawler/kuai_shou/blogger"
+        next_cursor = ""
+        payload = json.dumps({
+            "account_id": url_id,
+            "sort_type": "最热",
+            "cursor": next_cursor
+        })
+        headers = {
+            'Content-Type': 'application/json'
+        }
+        time.sleep(random.randint(1, 5))
+        try:
+            response = requests.request("POST", url, headers=headers, data=payload)
+            response = response.json()
+            data_all_list = response["data"]
+            if data_all_list == None or len(data_all_list) == 0:
+                if int(response["cdoe"]) == 27006:
+                    Feishu.finish_bot("kuai_shou/blogger接口" + response["msg"],
+                                      "https://open.feishu.cn/open-apis/bot/v2/hook/575ca6a1-84b4-4a2f-983b-1d178e7b16eb",
+                                      "【快手 Token 使用提示 】")
+        except Exception as exc:
+            return False
+        data_list = data_all_list["data"]
+        for data in data_list:
+            like_count = data['like_count']
+            if int(like_count) >= 10000:
+                return True
+        return False
     @classmethod
     def get_nrxs(cls):
-        user = sqlCollect.get_machine_making_reflux("快手")
+        user = sqlCollect.get_machine_making_reflux("快手", "快手历史")
         if user == None:
             return
         user = [item[0] for item in user]
-        for id in user:
-            ks_id = cls.get_ks_account_id(id)
+        for uid in user:
+            print(f"账号id{uid}")
+            ks_id = cls.get_ks_account_id(uid)
+            if ks_id == None:
+                continue
             url = "https://k.kuaishou.com/rest/web/similar/simStar/list"
 
             payload = json.dumps({
@@ -70,24 +141,62 @@ class CLJX:
             if result == 1:
                 data = response["data"]
                 star_vo_list = data['starVoList']
+                if star_vo_list == []:
+                    sqlCollect.update_machine_making_reflux(uid)
+                    continue
+                # 修改状态
+                sqlCollect.update_machine_making_reflux(uid)
+                list = []
                 for star in star_vo_list:
-                    user_id = star['userId']
+                    star_id = star['starId']
                     name = star['name']
-                    account_id = cls.get_ks_account_id(str(user_id))
+                    time.sleep(1)
+                    account_id = cls.get_cljx_user(int(star_id))  # 获取用户主页id
                     if account_id:
-                        print(account_id)
+                        print(f"溯源账号id:{account_id}")
+
+                        time.sleep(1)
+                        like_count = cls.get_ks_list(account_id)  # 是否符合规则
+                        if like_count:
+                            status = 1
+                        else:
+                            status = 0
+                        sqlCollect.insert_user_data(uid, name,  account_id, "快手", status)
                         values = [
                             [
-                                id,
+                                uid,
                                 name,
-                                account_id
+                                account_id,
+                                status,
+                                "快手"
                             ]
                         ]
-                        Feishu.insert_columns("AIW2sNNjdhCgT3tug7sco7FGnse", '727a17', "ROWS", 1, 2)
+                        Feishu.insert_columns("AIW2sNNjdhCgT3tug7sco7FGnse", 'couJYt', "ROWS", 1, 2)
                         time.sleep(0.5)
-                        Feishu.update_values("AIW2sNNjdhCgT3tug7sco7FGnse", '727a17', "A2:Z2", values)
+                        Feishu.update_values("AIW2sNNjdhCgT3tug7sco7FGnse", 'couJYt', "A2:Z2", values)
+                        if status == 1:
+                            list.append(account_id)
+                if list:
+                    result = ','.join(list)
+                    values = [
+                        [
+                            "快手",
+                            result,
+                            "72777058",
+                            "5",
+                            "通用-安全分享",
+                            "AI片尾引导",
+                            "",
+                            "",
+                            "AI标题",
+                            "3",
+                            f"溯源账号:{uid}"
+                        ]
+                    ]
+                    Feishu.insert_columns("WGIYsSDdxhItBwtJ0xgc0yE7nEg", '0701bd', "ROWS", 1, 2)
+                    time.sleep(0.5)
+                    Feishu.update_values("WGIYsSDdxhItBwtJ0xgc0yE7nEg", '0701bd', "B2:Z2", values)
             else:
-                print("提示")
                 Feishu.finish_bot("Token 过期,请及时更换",
                                   "https://open.feishu.cn/open-apis/bot/v2/hook/575ca6a1-84b4-4a2f-983b-1d178e7b16eb",
                                   "【磁力聚星提示】")

+ 25 - 0
data_channel/ks_nrxs.py

@@ -0,0 +1,25 @@
+import requests
+import json
+
+class KsNrxs:
+    """
+    快手内容相似
+    """
+    @classmethod
+    def get_ks_nrxs(cls):
+        url = "http://8.217.190.241:8888/crawler/kuai_shou/recommend_user"
+
+        payload = json.dumps({
+            "account_id": "3xr7iqf2gvtnsps"
+        })
+        headers = {
+            'Content-Type': 'application/json'
+        }
+
+        response = requests.request("POST", url, headers=headers, data=payload)
+        response = response.json()
+        print(response.text)
+
+
+if __name__ == '__main__':
+    KsNrxs.get_ks_nrxs()

+ 24 - 3
ks_qpl_main.py

@@ -1,4 +1,25 @@
-from data_channel.qpl_ks import QplKs
+import schedule
+import time
 
-if __name__ == '__main__':
-    QplKs.ks_data_list()
+from data_channel.cljx_nrxs import CLJX
+# from data_channel.qpl_ks import QplKs
+
+
+def video_start():
+    print("任务开始...")
+
+    try:
+        CLJX.get_nrxs()
+        print("任务成功完成")
+    except Exception as e:
+        print(f"任务执行过程中发生错误: {e}")
+
+    print("任务结束")
+
+
+# 每天早上 6 点执行
+schedule.every().day.at("06:00").do(video_start)
+
+while True:
+    schedule.run_pending()
+    time.sleep(1)