renyupeng il y a 3 ans
Parent
commit
f66bd07d07
2 fichiers modifiés avec 186 ajouts et 0 suppressions
  1. 93 0
      Apietl/task/BytedanceMaterialRequest.py
  2. 93 0
      Apietl/task/KuaishouMaterialRequest.py

+ 93 - 0
Apietl/task/BytedanceMaterialRequest.py

@@ -0,0 +1,93 @@
+# Author renyupeng
+# coding=utf-8
+# @Time    : 2022/2/9 6:01 下午
+# @Site    : 
+# @File    : BytedanceMaterialRequest.py
+# @Software: PyCharm
+# @contact: renyupeng@c-top.com.cn
+# @Tel 1501435553
+import json
+import logging
+import random
+import requests
+from Apietl.conn.TidbConn import TidbConn
+from Apietl.utlis.Utils import Utils
+
+
+class BytedanceMaterialRequest:
+    def __init__(self):
+        self.conn = TidbConn.get_connection()
+        self.parm = Utils.get_args()
+        self.start_time = self.parm[0]
+        self.end_time = self.parm[1]
+
+    """随机获取一个服务器ip"""
+
+    def range_hosts(self):
+        numList = [193, 194, 196]
+        num = random.sample(numList, 1)[0]
+        url = """http://192.168.0.{num}:8085/bytedance/bytedanceController/getBytedanceVideoByAccountId""".format(
+            num=num)
+        return url
+
+    """切割数组长度"""
+
+    @staticmethod
+    def list_split(items, n):
+        return [items[i:i + n] for i in range(0, len(items), n)]
+
+    def getMaterialAdvertiser(self):
+        try:
+            sql = """
+            SET GLOBAL group_concat_max_len=102400;
+            select  account_id,group_concat(distinct material_id) from application.bytedance_material_video_report_daily_dw
+            where stat_datetime between {start_time} and {end_time}
+            and signature is null
+            group by account_id
+            """.format(start_time=self.start_time, end_time=self.end_time)
+            results = TidbConn.exec_sql(self.conn, sql)
+            return results
+
+        except Exception as e:
+            logging.error("getBytedanceVideoByAccountId Exception:{}.".format(e))
+            return None
+
+    def handler(self):
+        results = self.getMaterialAdvertiser()
+
+        headers = {
+            'Content-Type': 'application/json'
+        }
+        for result in results:
+            url = self.range_hosts()
+            account_id = result[0]
+            # print(account_id)
+            material_id = result[1]
+            material_ids = material_id.split(',')
+            if len(material_ids) >= 100:
+                material_list = BytedanceMaterialRequest.list_split(material_ids, 50)
+                for info in material_list:
+                    info = list(map(int, info))
+
+                    req_data = {"accountId": account_id, "materialIds": info}
+                    data = json.dumps(req_data)
+                    try:
+                        repo = requests.post(url=url, data=data, headers=headers)
+                        logging.info("post  getBytedanceVideoByAccountId response:{}".format(repo))
+
+                    except Exception as e:
+                        logging.error("""post getBytedanceVideoByAccountId error {e}""".format(e=e))
+            else:
+
+                try:
+
+                    req_datas = {"accountId": account_id, "materialIds": list(map(int, material_ids))}
+                    datas = json.dumps(req_datas)
+                    repo = requests.post(url=url, data=datas, headers=headers)
+                    logging.info("post  getBytedanceVideoByAccountId response:{}".format(repo))
+                except Exception as e:
+                    logging.error("""post getBytedanceVideoByAccountId error {e}""".format(e=e))
+
+
+if __name__ == '__main__':
+    BytedanceMaterialRequest().handler()

+ 93 - 0
Apietl/task/KuaishouMaterialRequest.py

@@ -0,0 +1,93 @@
+# Author renyupeng
+# coding=utf-8
+# @Time    : 2022/2/9 6:01 下午
+# @Site    : 
+# @File    : KuaishouMaterialRequest.py
+# @Software: PyCharm
+# @contact: renyupeng@c-top.com.cn
+# @Tel 1501435553
+import json
+import logging
+import random
+
+from Apietl.conn.TidbConn import TidbConn
+from Apietl.utlis.Utils import Utils
+import requests
+
+
+class KuaishouMaterialRequest:
+    def __init__(self):
+        self.conn = TidbConn.get_connection()
+        self.parm = Utils.get_args()
+        self.start_time = self.parm[0]
+        self.end_time = self.parm[1]
+
+    """随机获取一个服务器ip"""
+
+    def range_hosts(self):
+        numList = [193, 194, 196]
+        num = random.sample(numList, 1)[0]
+        url = """http://192.168.0.{num}:8083/kuaishou/kuaishouController/getKuaishouVideoByAccountId""".format(num=num)
+        return url
+
+    """切割数组长度"""
+
+    @staticmethod
+    def list_split(items, n):
+        return [items[i:i + n] for i in range(0, len(items), n)]
+
+    """获取缺失视频id的账户"""
+
+    def getMaterialAccount(self):
+        try:
+            sql = """
+            SET GLOBAL group_concat_max_len=102400;
+            select  account_id,group_concat(distinct photo_id) from application.kuaishou_material_video_report_daily_dw
+            where stat_date between {start_time} and {end_time}
+            and signature is null and photo_id!=0
+            group by account_id
+            """.format(start_time=self.start_time, end_time=self.end_time)
+            results = TidbConn.exec_sql(self.conn, sql)
+            return results
+
+        except Exception as e:
+            logging.error("KuaishouMaterialRequest Exception:{}.".format(e))
+            return None
+
+    def handler(self):
+        results = self.getMaterialAccount()
+        headers = {
+            'Content-Type': 'application/json'
+        }
+        for result in results:
+            url = self.range_hosts()
+            account_id = result[0]
+            # print(account_id)
+            material_id = result[1]
+            material_ids = material_id.split(',')
+            if len(material_ids) >= 100:
+                material_list = KuaishouMaterialRequest.list_split(material_ids, 50)
+                for info in material_list:
+                    info = list(info)
+                    req_data = {"accountId": account_id, "photoIds": info}
+                    data = json.dumps(req_data)
+                    try:
+                        repo = requests.post(url=url, data=data, headers=headers)
+                        logging.info("post  getKuaishouVideoByAccountId response:{}".format(repo))
+
+                    except Exception as e:
+                        logging.error("""post getKuaishouVideoByAccountId error {e}""".format(e=e))
+            else:
+
+                try:
+                    req_datas = {"accountId": account_id, "photoIds": list(material_ids)}
+                    datas = json.dumps(req_datas)
+                    repo = requests.post(url=url, data=datas, headers=headers)
+                    logging.info("post  getKuaishouVideoByAccountId response:{}".format(repo))
+                except Exception as e:
+                    logging.error("""post getKuaishouVideoByAccountId error {e}""".format(e=e))
+            # print(material_ids)
+
+
+if __name__ == '__main__':
+    KuaishouMaterialRequest().range_hosts()