|
@@ -17,12 +17,14 @@ max_workers = 10
|
|
|
count = []
|
|
|
t = du.get_n_days(-10)
|
|
|
|
|
|
-def get_adcreatives(account_id,access_token,flag): # 获取创意
|
|
|
+def get_adcreatives(account_id,access_token,flag,adc_ids,dt): # 获取创意
|
|
|
+
|
|
|
url = 'https://api.e.qq.com/v1.1/adcreatives/get'
|
|
|
li =[]
|
|
|
page = 1
|
|
|
|
|
|
while True:
|
|
|
+
|
|
|
parameters = {
|
|
|
'access_token': access_token,
|
|
|
'timestamp': int(time.time()),
|
|
@@ -30,12 +32,12 @@ def get_adcreatives(account_id,access_token,flag): # 获取创意
|
|
|
'fields': ('campaign_id', 'adcreative_id', 'adcreative_name', 'adcreative_elements', 'promoted_object_type', 'page_type',
|
|
|
'page_spec', 'link_page_spec', 'universal_link_url', 'promoted_object_id','site_set'),
|
|
|
"filtering": [{
|
|
|
- "field": "created_time",
|
|
|
- "operator": "GREATER_EQUALS",
|
|
|
- "values":
|
|
|
- [
|
|
|
- DateUtils.str_to_stamp(t)
|
|
|
- ]}],
|
|
|
+ "field": "adcreative_id",
|
|
|
+ "operator": "IN",
|
|
|
+ "values": adc_ids.split(',')
|
|
|
+
|
|
|
+
|
|
|
+ }],
|
|
|
"account_id": account_id,
|
|
|
"page": page,
|
|
|
"page_size": 100,
|
|
@@ -46,8 +48,10 @@ def get_adcreatives(account_id,access_token,flag): # 获取创意
|
|
|
if type(parameters[k]) is not str:
|
|
|
parameters[k] = json.dumps(parameters[k])
|
|
|
|
|
|
+
|
|
|
while True:
|
|
|
h = requests.get(url, params=parameters)
|
|
|
+
|
|
|
if h.status_code == 200:
|
|
|
r = h.json()
|
|
|
# print(r)
|
|
@@ -82,7 +86,7 @@ def get_adcreatives(account_id,access_token,flag): # 获取创意
|
|
|
i['adcreative_id'],i['adcreative_name'],i['campaign_id'],image,title,
|
|
|
i.get('promoted_object_type',''),i.get('page_type',''),
|
|
|
i['page_spec'].get('page_id',''),i.get('promoted_object_id',''),
|
|
|
- '','','MP'
|
|
|
+ '','','MP',account_id,dt
|
|
|
))
|
|
|
else:
|
|
|
if len(i['adcreative_elements'])>0:
|
|
@@ -106,7 +110,7 @@ def get_adcreatives(account_id,access_token,flag): # 获取创意
|
|
|
i['adcreative_id'], i['adcreative_name'], i['campaign_id'],image,title,
|
|
|
i.get('promoted_object_type', ''), i.get('page_type', ''),
|
|
|
i['page_spec'].get('page_id', ''), i.get('promoted_object_id', ''),
|
|
|
- ','.join(i['site_set']),description,'GDT'
|
|
|
+ ','.join(i['site_set']),description,'GDT',account_id,dt
|
|
|
|
|
|
)
|
|
|
)
|
|
@@ -124,12 +128,12 @@ def get_adcreatives(account_id,access_token,flag): # 获取创意
|
|
|
break
|
|
|
if len(li)>0:
|
|
|
print(f"{account_id}有创意:",len(li))
|
|
|
- sql='replace into adcreative_info values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s) '
|
|
|
+ sql='replace into adcreative_info values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s) '
|
|
|
db.quchen_text.executeMany(sql,li)
|
|
|
|
|
|
|
|
|
|
|
|
-def images_info_get(account_id,access_token): # 获取图片信息
|
|
|
+def images_info_get(account_id,access_token,image_ids): # 获取图片信息
|
|
|
|
|
|
fields = ('image_id','width','height','file_size','signature','preview_url')
|
|
|
interface = 'images/get'
|
|
@@ -152,12 +156,11 @@ def images_info_get(account_id,access_token): # 获取图片信息
|
|
|
parameters = {
|
|
|
"account_id": account_id,
|
|
|
"filtering":[{
|
|
|
- "field": "created_time",
|
|
|
- "operator": "GREATER_EQUALS",
|
|
|
- "values":
|
|
|
- [
|
|
|
- DateUtils.str_to_stamp(t)
|
|
|
- ]}],
|
|
|
+ "field": "image_id",
|
|
|
+ "operator": "IN",
|
|
|
+ "values": image_ids.split(',')
|
|
|
+
|
|
|
+ }],
|
|
|
"page": page,
|
|
|
"page_size": 100
|
|
|
}
|
|
@@ -225,7 +228,8 @@ def ad_info():
|
|
|
"""获取广告基础信息"""
|
|
|
|
|
|
|
|
|
-def get_ad_info(account_id, access_token, flag):
|
|
|
+def get_ad_info(account_id, access_token, flag,ad_ids,dt):
|
|
|
+
|
|
|
|
|
|
path = 'ads/get'
|
|
|
fields = ('ad_id', 'ad_name', 'adcreative_id', 'adgroup_id', 'campaign_id')
|
|
@@ -240,12 +244,11 @@ def get_ad_info(account_id, access_token, flag):
|
|
|
'nonce': str(time.time()) + str(random.randint(0, 999999)),
|
|
|
'fields': fields,
|
|
|
"filtering": [{
|
|
|
- "field": "created_time",
|
|
|
- "operator": "GREATER_EQUALS",
|
|
|
+ "field": "ad_id",
|
|
|
+ "operator": "IN",
|
|
|
"values":
|
|
|
- [
|
|
|
- DateUtils.str_to_stamp(t)
|
|
|
- ]}],
|
|
|
+ ad_ids.split(',')
|
|
|
+ }],
|
|
|
"account_id": account_id,
|
|
|
"page": page,
|
|
|
"page_size": 100,
|
|
@@ -255,8 +258,14 @@ def get_ad_info(account_id, access_token, flag):
|
|
|
for k in parameters:
|
|
|
if type(parameters[k]) is not str:
|
|
|
parameters[k] = json.dumps(parameters[k])
|
|
|
- r = requests.get(url, params=parameters).json()
|
|
|
|
|
|
+ while True:
|
|
|
+ r = requests.get(url, params=parameters).json()
|
|
|
+ code = r['code']
|
|
|
+ if code == 11017:
|
|
|
+ time.sleep(61)
|
|
|
+ else:
|
|
|
+ break
|
|
|
# print(r)
|
|
|
total_page = r['data']['page_info']['total_page']
|
|
|
|
|
@@ -268,12 +277,12 @@ def get_ad_info(account_id, access_token, flag):
|
|
|
if r.get("data"):
|
|
|
for i in r['data']['list']:
|
|
|
li.append((str(i['ad_id']), i['ad_name'], i['adcreative_id'], i['campaign_id'], i['adgroup_id'],
|
|
|
- account_id, flag))
|
|
|
+ account_id, flag, dt))
|
|
|
|
|
|
|
|
|
if li.__len__()>0:
|
|
|
print(f"{account_id}有广告:",li.__len__())
|
|
|
- sql = "replace into ad_info values(%s,%s,%s,%s,%s,%s,%s) "
|
|
|
+ sql = "replace into ad_info values(%s,%s,%s,%s,%s,%s,%s,%s) "
|
|
|
db.quchen_text.executeMany(sql, li)
|
|
|
db.close()
|
|
|
|
|
@@ -288,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')
|
|
|
+ fields = ('date', 'ad_id', 'cost', 'view_count', 'ctr', 'follow_count','web_order_count','order_amount')
|
|
|
li = []
|
|
|
page = 1
|
|
|
while True:
|
|
@@ -311,8 +320,15 @@ def ad_cost_day_gdt(account_id,access_token,st,et):
|
|
|
for k in parameters:
|
|
|
if type(parameters[k]) is not str:
|
|
|
parameters[k] = json.dumps(parameters[k])
|
|
|
- r = requests.get(url, params=parameters).json()
|
|
|
+
|
|
|
+ while True:
|
|
|
+ r = requests.get(url, params=parameters).json()
|
|
|
# print(r)
|
|
|
+ code =r['code']
|
|
|
+ if code==11017:
|
|
|
+ time.sleep(61)
|
|
|
+ else:
|
|
|
+ break
|
|
|
|
|
|
if r.get("data"):
|
|
|
for i in r['data']['list']:
|
|
@@ -320,7 +336,7 @@ def ad_cost_day_gdt(account_id,access_token,st,et):
|
|
|
li.append(
|
|
|
(
|
|
|
i['date'], i['ad_id'], i['cost']/100, i['view_count'], i['ctr']*i['view_count'],
|
|
|
- i['follow_count']
|
|
|
+ i['follow_count'],i['web_order_count'],i['order_amount'],account_id,'GDT'
|
|
|
)
|
|
|
)
|
|
|
|
|
@@ -332,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)', li)
|
|
|
+ db.quchen_text.executeMany('replace into ad_cost_day values(%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')
|
|
|
+ fields = ('date', 'ad_id', 'cost', 'view_count', 'valid_click_count', 'official_account_follow_count','order_count','order_amount')
|
|
|
li = []
|
|
|
page = 1
|
|
|
while True:
|
|
@@ -361,8 +377,14 @@ def ad_cost_day_mp(account_id,access_token,st,et):
|
|
|
if type(parameters[k]) is not str:
|
|
|
parameters[k] = json.dumps(parameters[k])
|
|
|
|
|
|
- r = requests.get(url, params=parameters).json()
|
|
|
-
|
|
|
+ while True:
|
|
|
+ r = requests.get(url, params=parameters).json()
|
|
|
+ # print(r)
|
|
|
+ code = r['code']
|
|
|
+ if code == 11017:
|
|
|
+ time.sleep(61)
|
|
|
+ else:
|
|
|
+ break
|
|
|
|
|
|
if r.get("data"):
|
|
|
for i in r['data']['list']:
|
|
@@ -370,7 +392,8 @@ def ad_cost_day_mp(account_id,access_token,st,et):
|
|
|
li.append(
|
|
|
(
|
|
|
i['date'],i['ad_id'],i['cost']/100,i['view_count'],i['valid_click_count'],
|
|
|
- i['official_account_follow_count']
|
|
|
+ i['official_account_follow_count'],i['order_count'],i['order_amount'],account_id,'MP'
|
|
|
+
|
|
|
)
|
|
|
)
|
|
|
|
|
@@ -382,7 +405,7 @@ def ad_cost_day_mp(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)', li)
|
|
|
+ db.quchen_text.executeMany('replace into ad_cost_day values(%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投放计划日报数据
|