Browse Source

抖音相似溯源

zhangyong 8 months ago
parent
commit
d67f4c181b
3 changed files with 131 additions and 2 deletions
  1. 53 0
      common/redis.py
  2. 1 1
      data_channel/dy_ls.py
  3. 77 1
      data_channel/dy_nrxs.py

+ 53 - 0
common/redis.py

@@ -0,0 +1,53 @@
+import redis
+from datetime import timedelta
+
+
+class SyncRedisHelper:
+    _pool: redis.ConnectionPool = None
+    _instance = None
+
+    def __init__(self):
+        if not self._instance:
+            self._pool = self._get_pool()
+            self._instance = self
+
+    def _get_pool(self) -> redis.ConnectionPool:
+        if self._pool is None:
+            self._pool = redis.ConnectionPool(
+                # host="r-bp1mb0v08fqi4hjffu.redis.rds.aliyuncs.com",  # 内网地址
+                host="r-bp1mb0v08fqi4hjffupd.redis.rds.aliyuncs.com",  # 外网地址
+                port=6379,
+                db=0,
+                password="Wqsd@2019",
+                # password="Qingqu2019",
+
+            )
+        return self._pool
+
+    def get_client(self) -> redis.Redis:
+        pool = self._get_pool()
+        client = redis.Redis(connection_pool=pool)
+        return client
+
+    def close(self):
+        if self._pool:
+            self._pool.disconnect(inuse_connections=True)
+
+
+def get_data(name, data):
+    key = f"task:{name}"
+    helper = SyncRedisHelper()
+    client = helper.get_client()
+    if not client.exists('wangxueke-task'):
+        acquire_lock = client.set('wangxueke-lock', 1, ex=600, nx=True)
+        if not acquire_lock:
+            return
+        data = [{}, {}, {}]
+        client.rpush('wangxueke-task', *data)
+    return client.lpop('wangxueke-task')
+
+value = get_data('xiaoniangao', '1234857')
+if value is None:
+    print("Value does not exist")
+else:
+    print(f"Retrieved value: {value}")

+ 1 - 1
data_channel/dy_ls.py

@@ -13,7 +13,7 @@ class DYLS:
     @classmethod
     def get_dyls_list(cls, task_mark, url_id, number, mark):
         next_cursor = ""
-        for i in range(20):
+        for i in range(10):
             list = []
             try:
                 #  抖查查

+ 77 - 1
data_channel/dy_nrxs.py

@@ -1,3 +1,11 @@
+import time
+
+import requests
+import json
+
+from common import Feishu
+from common.sql_help import sqlCollect
+
 
 class DYNrxs:
     """
@@ -5,4 +13,72 @@ class DYNrxs:
     """
     @classmethod
     def get_dy_nrxs(cls):
-        pass
+        user = sqlCollect.get_machine_making_reflux("抖音", "抖音历史")
+        if user == None:
+            return
+        user = [item[0] for item in user]
+        for uid in user:
+            url = "http://8.217.190.241:8888/crawler/dou_yin/recommend_user"
+
+            payload = json.dumps({
+                "account_id": uid,
+                "cursor": ""
+            })
+            headers = {
+                'Content-Type': 'application/json'
+            }
+
+            response = requests.request("POST", url, headers=headers, data=payload)
+            response = response.json()
+            code = response['code']
+            if code == 0:
+                data_list = response['data']['data']
+                if data_list == []:
+                    sqlCollect.update_machine_making_reflux(uid)
+                    continue
+                sqlCollect.update_machine_making_reflux(uid)
+                list = []
+                for data in data_list:
+                    name = data['nickname']
+                    sec_uid = data['sec_uid']
+                    time.sleep(1)
+                    values = [
+                        [
+                            uid,
+                            name,
+                            sec_uid
+                        ]
+                    ]
+                    Feishu.insert_columns("AIW2sNNjdhCgT3tug7sco7FGnse", 'GO3Abg', "ROWS", 1, 2)
+                    time.sleep(0.5)
+                    Feishu.update_values("AIW2sNNjdhCgT3tug7sco7FGnse", 'GO3Abg', "A2:Z2", values)
+                    list.append(sec_uid)
+                if list:
+                    result = ','.join(list)
+                    values = [
+                        [
+                            "抖音",
+                            result,
+                            "72804451",
+                            "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:
+                Feishu.finish_bot("dou_yin/recommend_user 请求失败",
+                                  "https://open.feishu.cn/open-apis/bot/v2/hook/575ca6a1-84b4-4a2f-983b-1d178e7b16eb",
+                                  "【抖音接口使用提示】")
+
+
+
+if __name__ == '__main__':
+    DYNrxs.get_dy_nrxs()