ad批量上传
import pandas as pd import requests import arrow from collections import deque import json campaign_name_deq = deque(['1'],2) ad_name_deq = deque(['1'],2) Today = arrow.now().format("YYYY-MM-DD") headers = { xxx } def get_excel_data(): data = pd.read_excel('./multi_xx.xlsx') user_id = data['xxD'].tolist() campaign_name = data['计xx'].tolist() ad_name = data['xxx'].tolist() creative_name = data['创xx'].tolist() creative_title = data['xx'].tolist() creative_desc = data['xx'].tolist() creative_ldpUrl = data['xxxurl'].tolist() return [user_id,campaign_name,ad_name,creative_name,creative_title,creative_desc,creative_ldpUrl] def get_productId(userId): url = f'hxxxx={userId}' res = requests.get(url, headers=headers) data = res.json()['result'][0]['id'] return data def add_new_campaign(userId, campaignName): url = 'hxxxxx' data = { xxx } res = requests.post(url, headers=headers, data=json.dumps(data)) campaign_id = res.json()['id'] print(campaignName,campaign_id) status = res.json()["status"] return campaign_id, status def add_new_ad(campaignId, adName): url = 'hxxxxx' data = { x "appInstall": None, x }, } res = requests.post(url, headers=headers, data=json.dumps(data)) adId = res.json()['id'] status = res.json()["status"] print(adName, adId,status) return adId, status def add_new_creative_word(adId, name, title, desc, ldpUrl): url = 'htxxxxxx' data = { "xx } res = requests.post(url, headers=headers, data=json.dumps(data)) status = res.json()["status"] print(adId,name, status) adId, ad_status = 0,'' def gen_creative(userid, campaign_name, ad_name, creative_name, creative_title, creative_desc, creative_ldpUrl): campaign_name_deq.append(campaign_name) last_campaign_name = campaign_name_deq.popleft() ad_name_deq.append(ad_name) last_ad_name = ad_name_deq.popleft() campaign_id, campaign_status = 0,'' if campaign_name != last_campaign_name: campaign_id, campaign_status = add_new_campaign(userid, campaign_name) if campaign_status == 'ok' and ad_name != last_ad_name: global adId, ad_status adId, ad_status = add_new_ad(campaign_id, ad_name) if ad_status == 'ok': add_new_creative_word(adId, creative_name, creative_title, creative_desc, creative_ldpUrl) else: print(adId,ad_status) def mulit_upload(): l = get_excel_data() a = list(map(gen_creative,*l)) if __name__ == '__main__': mulit_upload()