|
@@ -297,7 +297,7 @@ def get_ad_cost_day(account_id,access_token,flag,st,et):
|
|
|
|
|
|
def ad_cost_day_gdt(account_id,access_token,st,et):
|
|
|
url = 'https://api.e.qq.com/v1.3/daily_reports/get'
|
|
|
- fields = ('date', 'ad_id', 'cost', 'view_count', 'ctr', 'follow_count','web_order_count','order_amount')
|
|
|
+ fields = ('date', 'ad_id','adgroup_id', 'cost', 'view_count', 'ctr', 'follow_count','web_order_count','order_amount')
|
|
|
li = []
|
|
|
page = 1
|
|
|
while True:
|
|
@@ -335,7 +335,7 @@ def ad_cost_day_gdt(account_id,access_token,st,et):
|
|
|
if i['cost']>0:
|
|
|
li.append(
|
|
|
(
|
|
|
- i['date'], i['ad_id'], i['cost']/100, i['view_count'], i['ctr']*i['view_count'],
|
|
|
+ i['date'], i['ad_id'],i['adgroup_id'], i['cost']/100, i['view_count'], i['ctr']*i['view_count'],
|
|
|
i['follow_count'],i['web_order_count'],i['order_amount']/100,account_id,'GDT'
|
|
|
)
|
|
|
)
|
|
@@ -348,13 +348,13 @@ def ad_cost_day_gdt(account_id,access_token,st,et):
|
|
|
# print(li)
|
|
|
if len(li) > 0:
|
|
|
print(f"{account_id} have ad cost :{len(li)} ")
|
|
|
- db.quchen_text.executeMany('replace into ad_cost_day values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)', li)
|
|
|
+ db.quchen_text.executeMany('replace into ad_cost_day values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)', li)
|
|
|
db.close()
|
|
|
|
|
|
|
|
|
def ad_cost_day_mp(account_id,access_token,st,et):
|
|
|
url = 'https://api.e.qq.com/v1.3/daily_reports/get'
|
|
|
- fields = ('date', 'ad_id', 'cost', 'view_count', 'valid_click_count', 'official_account_follow_count','order_count','order_amount')
|
|
|
+ fields = ('date', 'ad_id','adgroup_id', 'cost', 'view_count', 'valid_click_count', 'official_account_follow_count','order_count','order_amount')
|
|
|
li = []
|
|
|
page = 1
|
|
|
while True:
|
|
@@ -379,7 +379,10 @@ def ad_cost_day_mp(account_id,access_token,st,et):
|
|
|
|
|
|
while True:
|
|
|
r = requests.get(url, params=parameters).json()
|
|
|
- # print(r)
|
|
|
+ # print(r['data']['list'])
|
|
|
+ # import pandas as pd
|
|
|
+ # print(pd.DataFrame(r['data']['list']))
|
|
|
+
|
|
|
code = r['code']
|
|
|
if code == 11017:
|
|
|
time.sleep(61)
|
|
@@ -391,7 +394,7 @@ def ad_cost_day_mp(account_id,access_token,st,et):
|
|
|
if i['cost']>0:
|
|
|
li.append(
|
|
|
(
|
|
|
- i['date'],i['ad_id'],i['cost']/100,i['view_count'],i['valid_click_count'],
|
|
|
+ i['date'],i['ad_id'],i['adgroup_id'],i['cost']/100,i['view_count'],i['valid_click_count'],
|
|
|
i['official_account_follow_count'],i['order_count'],i['order_amount']/100,account_id,'MP'
|
|
|
|
|
|
)
|
|
@@ -403,9 +406,10 @@ def ad_cost_day_mp(account_id,access_token,st,et):
|
|
|
else:
|
|
|
page += 1
|
|
|
# print(li)
|
|
|
+ # exit()
|
|
|
if len(li) > 0:
|
|
|
print(f"{account_id} have ad cost :{len(li)} ")
|
|
|
- db.quchen_text.executeMany('replace into ad_cost_day values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)', li)
|
|
|
+ db.quchen_text.executeMany('replace into ad_cost_day values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)', li)
|
|
|
db.close()
|
|
|
|
|
|
def daily_reports_get(access_token, account_id, level, start_date, end_date, fields): # 获取wx投放计划日报数据
|
|
@@ -524,12 +528,12 @@ def mysql_insert_adcreative(data):
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
- account_id = 19016239
|
|
|
- access_token = '65407243a6072b7dee3a013b58225e16'
|
|
|
+ account_id = 14629666
|
|
|
+ access_token = 'e1c074d5e1a71435a52c1078f9d5804c'
|
|
|
#
|
|
|
account_id2 = 14709511
|
|
|
access_token2 = 'e87f7b6f860eaeef086ddcc9c3614678'
|
|
|
- # get_ad_cost_day(account_id2,access_token2,'GDT','2021-03-01','2021-03-24')
|
|
|
+ get_ad_cost_day(account_id,access_token,'MP','2021-04-05','2021-04-05')
|
|
|
|
|
|
|
|
|
|