| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 | 
							- # 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 >= {start_time} and stat_date<={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}
 
-                     print(11111,req_data)
 
-                     data = json.dumps(req_data)
 
-                     try:
 
-                         repo = requests.post(url=url, data=data, headers=headers)
 
-                         print(22222,repo)
 
-                         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)}
 
-                     print(333333,req_datas)
 
-                     datas = json.dumps(req_datas)
 
-                     repo = requests.post(url=url, data=datas, headers=headers)
 
-                     print(44444,repo)
 
-                     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().handler()
 
 
  |