from v3modules import DCMAPI, CreativeUtils, CampaignUtils

Api = DCMAPI.DCMAPI()

def activateCreative(creativeAssets):
    for asset in creativeAssets:
        asset["active"] = True
    return creativeAssets


listValues = {"archived":False, "searchString":"2019","subaccountId":"23262"}
campaignList = CampaignUtils.getCampaignList(Api, listValues)


for campaign in campaignList:
    listValues = {"active": True, "archived": False,"campaignId":campaign["id"]}
    creativeList = CreativeUtils.listCreatives(Api, listValues)
    for creative in creativeList:
        try:
            assets = [x for x in creative["creativeAssets"] if x["active"] == False]
        except:
            continue
        if len(assets) == 0:
            continue
        else:
            creativeAssets = activateCreative(creative["creativeAssets"])
            payload =  {"creativeAssets": creativeAssets}
            CreativeUtils.updateCreative(Api, creative["id"], payload)

Exemple #2
0
from v3modules import CampaignUtils, DCMAPI, AdUtils, UtilUtils
import datetime
import pandas as pd

Api = DCMAPI.DCMAPI()
AdList = []


def compareAdDates(ad):
    today = datetime.datetime(2017, 1, 1, 12)
    adDate = datetime.datetime.strptime(ad["endTime"], "%Y-%m-%dT%H:%M:%S.%fZ")
    return today > adDate


listValues = {"subaccountId": 28400, "archived": False}
CanadaCampaigns = CampaignUtils.getCampaignList(Api, listValues)
for campaign in CanadaCampaigns:
    print("Analyzing {campaignName}".format(campaignName=campaign["name"]))
    listValues = {
        "campaignIds": campaign["id"],
        "active": True,
        "archived": False
    }
    ads = AdUtils.listAd(Api, listValues)
    ads = [x for x in ads if compareAdDates(x)]
    for ad in ads:
        AdUtils.deactivateAd(ad["id"], Api)
        AdList.append({
            "name": ad["name"],
            "id": ad["id"],
            "campaign name": campaign["name"],