Is there any way to fetch adgroups/campaigns sorted by last updated time. Currently I am fetching data using these methods. What changes should I make ?
def fetch_adgroups(self, login_id=None, campaign_ids=None):
""" Fetches ad groups from Google.
Note: The AdWords API limits the number of results per request:
To successfully retrieve results, we chunk our requests by campaign ID.
Args:
campaign_ids: optional, filter by campaigns
"""
logging.info('Fetching ad groups from Google.')
if campaign_ids:
logging.info('Filtering on %s campaign IDs.', len(campaign_ids))
query = """
SELECT
ad_group.status
FROM ad_group
WHERE ad_group.status = 'ENABLED'"""
if campaign_ids:
campaign_ids_str = "','".join(map(str, campaign_ids))
adgroups = []
for row in self.__make_search(query, self.adwords_customer_id, True, login_id):
adgroups.append(zeep_helpers.serialize_object(row))
logging.info('Fetched %s ad groups from Google.', len(adgroups))
return adgroups
def fetch_campaigns(self, login_id=None):
""" Fetches campaigns from Google."""
logging.info('Fetching campaigns from Google.')
query = """
SELECT
campaign.status
FROM campaign
WHERE campaign.status = 'ENABLED'
campaigns = []
for row in self.__make_search(query, self.adwords_customer_id, True, login_id):
campaigns.append(zeep_helpers.serialize_object(row))
logging.info('Fetched %s campaigns from Google.', len(campaigns))
return campaigns