Exemple #1
0
    def set_domains(self, domains, sitelist_id=None):

        # get the campaign so we can get the advertiserId
        loader = Campaign(Base.connection)
        campaign = json.loads(loader.find(self.data['CampaignId']))

        # get the sitelist
        loader = SiteList(Base.connection)
        if sitelist_id is not None:
            sitelist = json.loads(loader.find(sitelist_id))
        else:
            sitelist = json.loads(loader.find_by_name(campaign.get('data').get('AdvertiserId'), self.data['AdGroupName']))

        if sitelist.get('data').get('ResultCount') == 0:
            sitelist = SiteList(Base.connection)
            sitelist['SiteListName'] = self.data['AdGroupName']
            sitelist['AdvertiserId'] = campaign.get('data').get('AdvertiserId')
            sitelist.set_domains(domains)
            response = json.loads(sitelist.create())
        else:
            try:
                sitelist_data = sitelist.get('data').get('Result')[0]
            except:
                sitelist_data = sitelist.get('data')
            sitelist = SiteList(Base.connection, sitelist_data)
            sitelist.set_domains(domains)
            sitelist['SiteListId'] = sitelist_data.get('SiteListId')
            sitelist['SiteListName'] = self.data['AdGroupName'][:255]
            response = json.loads(sitelist.save(sitelist))

        if 'RTBAttributes' not in self:
            self['RTBAttributes'] = {}

        # sitelist.getId() always exists so set as default list
        if 'SiteTargeting' in self.data['RTBAttributes']:
            # If Ad Group as a current list, use it and append the new ID.
            if 'SiteListIds' in self.data['RTBAttributes']['SiteTargeting']:
                currentList = self.data['RTBAttributes']['SiteTargeting']['SiteListIds']
                if sitelist.getId() not in currentList:
                    currentList.append(sitelist.getId())
        else:
            currentList = [sitelist.getId()]
            #currentList = [response.get('data').get('SiteListId')]

        if len(domains) == 0 and sitelist.getId() in currentList:
            currentList.remove(sitelist.getId())
            #currentList.remove(response.get('data').get('SiteListId'))

        if len(currentList) == 0:
            self['RTBAttributes']['SiteTargeting'] = {
                'SiteListIds': [],
                'SiteListFallThroughAdjustment': 1
                }
        else:
            self['RTBAttributes']['SiteTargeting'] = {
                'SiteListIds': currentList,
                'SiteListFallThroughAdjustment': 0
                }

        return response
Exemple #2
0
    def set_domains(self, domains):

        # get the campaign so we can get the advertiserId
        loader = Campaign(Base.connection)
        campaign = loader.find(self['CampaignId'])
        
        # get the sitelist
        loader = SiteList(Base.connection)
        sitelist = loader.find_by_name(campaign['AdvertiserId'], self['AdGroupName'])
        if sitelist == None:
            sitelist = SiteList(Base.connection)
            sitelist['SiteListName'] = self['AdGroupName']
            sitelist['AdvertiserId'] = campaign['AdvertiserId']

        sitelist.set_domains(domains)
        if sitelist.getId() == 0 or sitelist.getId() is None:
            sitelist.create()
        else:
            sitelist.save()

        if 'RTBAttributes' not in self:
            self['RTBAttributes'] = {}
            
        self['RTBAttributes']['SiteTargeting'] = { 
            'SiteListIds': [sitelist.getId()],
            'SiteListFallThroughAdjustment': 0
            }
Exemple #3
0
    def set_domains(self, domains, sitelist_id=None):

        # get the campaign so we can get the advertiserId
        loader = Campaign(Base.connection)
        campaign = loader.find(self['CampaignId'])

        # get the sitelist
        loader = SiteList(Base.connection)
        if sitelist_id is not None:
            sitelist = loader.find(sitelist_id)
        else:
            sitelist = loader.find_by_name(campaign['AdvertiserId'], self['AdGroupName'])

        if sitelist == None:
            sitelist = SiteList(Base.connection)
            sitelist['SiteListName'] = self['AdGroupName']
            sitelist['AdvertiserId'] = campaign['AdvertiserId']

        sitelist.set_domains(domains)
        if sitelist.getId() == 0 or sitelist.getId() is None:
            sitelist.create()
        else:
            sitelist.save()

        if 'RTBAttributes' not in self:
            self['RTBAttributes'] = {}

        # sitelist.getId() always exists so set as default list
        if 'SiteTargeting' in self['RTBAttributes']:
            # If Ad Group as a current list, use it and append the new ID.
            if 'SiteListIds' in self['RTBAttributes']['SiteTargeting']:
                currentList = self['RTBAttributes']['SiteTargeting']['SiteListIds']

                # Weird error if duplicate IDs exist
                """
                Exception: Bad response code {"Message":"The request failed validation. Please check your request and try again.","ErrorDetails":[{"Property":"AdGroup.RTBAttributes.SiteTargeting.SiteListIds","Reasons":["The following Site Lists cannot be used for this operation because they are not accessible to Advertiser '9ut3ufp': ."]}]}
                """
                if sitelist.getId() not in currentList:
                    currentList.append(sitelist.getId())
        else:
            currentList = [sitelist.getId()]

        if len(domains) == 0 and sitelist.getId() in currentList:
            currentList.remove(sitelist.getId())

        if len(currentList) == 0:
            self['RTBAttributes']['SiteTargeting'] = {
                'SiteListIds': [],
                'SiteListFallThroughAdjustment': 1
                }
        else:
            self['RTBAttributes']['SiteTargeting'] = {
                'SiteListIds': currentList,
                'SiteListFallThroughAdjustment': 0
                }

        return sitelist.getId()