from app.api_data.cost_util import * from model.DateUtils import DateUtils from model.DataBaseUtils import MysqlUtils from concurrent.futures import ThreadPoolExecutor db = MysqlUtils() du = DateUtils() max_workers =10 def get_accounts(filter=None): if filter: if filter=='MP': return db.quchen_text.getData("select account_id,access_token,name channel from advertiser_vx where (name !='' or name is not null)") else: return db.quchen_text.getData("select account_id,access_token,name channel from advertiser_qq where (name !='' or name is not null)") return db.quchen_text.getData("select account_id,access_token,name channel,'MP' flag from advertiser_vx where (name !='' or name is not null) union " "select account_id,access_token,name channel,'GDT' flag from advertiser_qq where (name !='' or name is not null)") def ad(dt): sql =f"""SELECT b.account_id,b.access_token,b.type,GROUP_CONCAT(ad_id) from ad_cost_day 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}' 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(get_ad_info, account[0], account[1], account[2],account[3],dt) executor.shutdown() """广告日消耗""" def ad_cost_day(dt): st = et = dt executor = ThreadPoolExecutor(max_workers=max_workers) for account in get_accounts(): executor.submit(get_ad_cost_day, account[0], account[1],account[3],st,et) executor.shutdown() def adcreative(dt): sql = f"""SELECT b.account_id,b.access_token,b.type,GROUP_CONCAT(adcreative_id) from ad_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}' 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(get_adcreatives, account[0], account[1],account[2],account[3],dt) executor.shutdown() def image(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}' 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(images_info_get, account[0], account[1], account[3]) executor.shutdown() def day(): """ 1.拉取有消耗的广告 2.用有消耗的广告id 去拉取广告基础信息 3.用第2步获取的创意id 去拉取广告创意基础信息 4.用创意信息中的图片id 去获取图片的基础信息 """ dt = du.getNow() ad_cost_day(dt) ad(dt) adcreative(dt) image(dt) if __name__ == '__main__': # MP # account_id = 18516323 # access_token = '262deda76aec00c2e144e83bd3c0b2a2' # # account_id2= 14709511 # access_token2 = 'e87f7b6f860eaeef086ddcc9c3614678' # run() # ad_cost_day() # day()