ck 3 rokov pred
rodič
commit
44dd1da498
2 zmenil súbory, kde vykonal 85 pridanie a 3 odobranie
  1. 66 1
      app/api_data/cost_util.py
  2. 19 2
      app/api_data/get_cost.py

+ 66 - 1
app/api_data/cost_util.py

@@ -148,7 +148,6 @@ def images_info_get(account_id,access_token,image_ids):  # 获取图片信息
     li = []
 
 
-
     while True:
 
         common_parameters = {
@@ -206,6 +205,72 @@ def images_info_get(account_id,access_token,image_ids):  # 获取图片信息
         db.close()
 
 
+def video_info_get(account_id,access_token,image_ids):  # 获取视频信息
+
+    fields = ('video_id','width','height','file_size','signature','preview_url')
+    interface = 'videos/get'
+    url = 'https://api.e.qq.com/v1.3/' + interface
+
+    page = 1
+    li = []
+
+
+    while True:
+
+        common_parameters = {
+            'access_token': access_token,
+            'timestamp': int(time.time()),
+            'nonce': str(time.time()) + str(random.randint(0, 999999)),
+            'fields': fields
+        }
+
+        parameters = {
+            "account_id": account_id,
+            "filtering":[{
+                    "field": "media_id",
+                    "operator": "IN",
+                    "values": image_ids.split(',')
+
+                    }],
+            "page": page,
+            "page_size": 100
+        }
+
+        parameters.update(common_parameters)
+        for k in parameters:
+            if type(parameters[k]) is not str:
+                parameters[k] = json.dumps(parameters[k])
+
+        while True:
+            h = requests.get(url, params=parameters)
+            # print(h.text)
+            if h.status_code == 200:
+                r = h.json()
+                break
+            else:
+                time.sleep(1)
+                print("请求出错 等待1s..")
+
+        if 'data' in r.keys():
+            li.extend(r['data']['list'])
+
+
+        total_page = r['data']['page_info']['total_page']
+        if total_page > page:
+            page += 1
+        else:
+            break
+    # print(li)
+    data = []
+    for i in li:
+        data.append((i['video_id'],i['width'],i['height'],i['signature'],i['preview_url']))
+    # print(data)
+    print(f"{account_id} 有视频:", li.__len__())
+    if li.__len__() > 0:
+        sql="replace into video_info value (%s,%s,%s,%s,%s)"
+        db.quchen_text.executeMany(sql, data)
+        db.close()
+
 
 def ad_info():
     accounts = db.quchen_text.getData("""

+ 19 - 2
app/api_data/get_cost.py

@@ -76,7 +76,7 @@ left join (
 select account_id,access_token,'MP' type  from advertiser_vx where (name !='' or name is not null) union 
 select account_id,access_token,'GDT' type from advertiser_qq where (name !='' or name is not null)
 ) b on a.account_id=b.account_id
-where a.dt='{dt}'
+where a.dt='{dt}' and a.is_video=0
 GROUP BY b.account_id,b.access_token,b.type"""
 	accounts = db.quchen_text.getData(sql)
 	executor = ThreadPoolExecutor(max_workers=max_workers)
@@ -85,6 +85,20 @@ GROUP BY b.account_id,b.access_token,b.type"""
 	executor.shutdown()
 
 
+def video(dt):
+	sql = f"""SELECT b.account_id,b.access_token,b.type,GROUP_CONCAT(image_id)  from adcreative_info  a
+	left join (
+	select account_id,access_token,'MP' type  from advertiser_vx where (name !='' or name is not null) union 
+	select account_id,access_token,'GDT' type from advertiser_qq where (name !='' or name is not null)
+	) b on a.account_id=b.account_id
+	where a.dt='{dt}' and a.is_video=1
+	GROUP BY b.account_id,b.access_token,b.type"""
+	accounts = db.quchen_text.getData(sql)
+	executor = ThreadPoolExecutor(max_workers=max_workers)
+	for account in accounts:
+		executor.submit(video_info_get, account[0], account[1], account[3])
+	executor.shutdown()
+
 def run(dt):
 	"""
 		1.拉取有消耗的广告
@@ -98,6 +112,8 @@ def run(dt):
 		ad(dt)
 		adcreative(dt)
 		image(dt)
+		video(dt)
+
 	except:
 		DingTalkUtils.send("拉取广告数据出错")
 
@@ -125,7 +141,8 @@ if __name__ == '__main__':
 
 	# day()
 	# run('2021-05-10')
-	adcreative('2021-05-11')
+	# adcreative('2021-05-11')
+	video('2021-05-14')
 	# for dt in list(reversed(du.getDateLists('2020-04-08','2021-04-09'))):
 	# 	print(dt)
 	# 	ad(dt)