Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def archive_order_by_name(order_name):
"""
Archives an order by name in DFP.
Args:
order_name (str): the name of the DFP order to archive
Returns:
None
"""
client = get_client()
order_service = client.GetService('OrderService', version='v201908')
statement = (ad_manager.StatementBuilder()
.Where('name = :name')
.WithBindVariable('name', order_name))
response = order_service.performOrderAction(
{'xsi_type': 'ArchiveOrders'},
statement.ToStatement())
def main(client, key_id):
# Initialize appropriate service.
custom_targeting_service = client.GetService(
'CustomTargetingService', version='v201905')
statement = (ad_manager.StatementBuilder(version='v201905')
.Where('id = :keyId')
.WithBindVariable('keyId', int(key_id))
.Limit(1))
# Get custom targeting keys by statement.
response = custom_targeting_service.getCustomTargetingKeysByStatement(
statement.ToStatement())
# Update each local custom targeting key object by changing its display name.
if 'results' in response and len(response['results']):
updated_keys = []
for key in response['results']:
if not key['displayName']:
key['displayName'] = key['name']
key['displayName'] += ' (Deprecated)'
updated_keys.append(key)
def main(client, contact_id):
# Initialize appropriate service.
contact_service = client.GetService('ContactService', version='v201808')
# Create statement object to select the single contact by ID.
statement = (ad_manager.StatementBuilder(version='v201808')
.Where('id = :id')
.WithBindVariable('id', long(contact_id))
.Limit(1))
# Get contacts by statement.
response = contact_service.getContactsByStatement(
statement.ToStatement())
if 'results' in response and len(response['results']):
updated_contacts = []
for contact in response['results']:
contact['address'] = '123 New Street, New York, NY, 10011'
updated_contacts.append(contact)
# Update the contact on the server.
contacts = contact_service.updateContacts(updated_contacts)
def main(client, saved_query_id):
# Initialize appropriate service.
report_service = client.GetService('ReportService', version='v201811')
# Initialize a DataDownloader.
report_downloader = client.GetDataDownloader(version='v201811')
# Create statement object to filter for an order.
statement = (ad_manager.StatementBuilder(version='v201811')
.Where('id = :id')
.WithBindVariable('id', int(saved_query_id))
.Limit(1))
response = report_service.getSavedQueriesByStatement(
statement.ToStatement())
if 'results' in response and len(response['results']):
saved_query = response['results'][0]
if saved_query['isCompatibleWithApiVersion']:
report_job = {}
# Set report query and optionally modify it.
report_job['reportQuery'] = saved_query['reportQuery']
def main(client, product_id):
# Initialize appropriate service.
product_service = client.GetService('ProductService', version='v201711')
# Create query.
statement = (dfp.StatementBuilder()
.Where('id = :id')
.WithBindVariable('id', long(product_id))
.Limit(1))
products_published = 0
# Get products by statement.
while True:
response = product_service.getProductsByStatement(
statement.ToStatement())
if 'results' in response:
for product in response['results']:
print ('Product with id "%s" and name "%s" will be '
'published.' % (product['id'],
product['name']))
def main(client, order_id):
# Initialize appropriate service.
line_item_service = client.GetService('LineItemService', version='v201802')
# Create statement object to only select line items with even delivery rates.
statement = (dfp.StatementBuilder()
.Where(('deliveryRateType = :deliveryRateType AND '
'orderId = :orderId'))
.WithBindVariable('orderId', long(order_id))
.WithBindVariable('deliveryRateType', 'EVENLY')
.Limit(500))
# Get line items by statement.
response = line_item_service.getLineItemsByStatement(
statement.ToStatement())
if 'results' in response and len(response['results']):
# Update each local line item by changing its delivery rate type.
updated_line_items = []
for line_item in response['results']:
if not line_item['isArchived']:
line_item['deliveryRateType'] = 'AS_FAST_AS_POSSIBLE'
def main(client):
# Initialize appropriate service.
campaign_service = client.GetService('CampaignService', version='v201802')
# Construct query and get all campaigns.
query = (adwords.ServiceQueryBuilder()
.Select('Id', 'Name', 'Status')
.Where('Status').EqualTo('ENABLED')
.OrderBy('Name')
.Limit(0, PAGE_SIZE)
.Build())
for page in query.Pager(campaign_service):
# Display results.
if 'entries' in page:
for campaign in page['entries']:
print ('Campaign with id "%s", name "%s", and status "%s" was '
'found.' % (campaign['id'], campaign['name'],
campaign['status']))
else:
print 'No campaigns were found.'
'FROM CRITERIA_PERFORMANCE_REPORT '
'WHERE Status IN [ENABLED, PAUSED] '
'DURING LAST_7_DAYS')
with open(path, 'w') as output_file:
report_downloader.DownloadReportWithAwql(
report_query, 'CSV', output_file, skip_report_header=False,
skip_column_header=False, skip_report_summary=False,
include_zero_impressions=True)
print 'Report was downloaded to "%s".' % path
if __name__ == '__main__':
# Initialize client object.
adwords_client = adwords.AdWordsClient.LoadFromStorage()
main(adwords_client, PATH)
if 'value' in ad_group_criteria:
for criterion in ad_group_criteria['value']:
if criterion['criterion']['Criterion.Type'] == 'Keyword':
print ('Ad group criterion with ad group id \'%s\' and criterion id '
'\'%s\' currently has bids:'
% (criterion['adGroupId'], criterion['criterion']['id']))
for bid in criterion['biddingStrategyConfiguration']['bids']:
print '\tType: \'%s\', value: %s' % (bid['Bids.Type'],
bid['bid']['microAmount'])
else:
print 'No ad group criteria were updated.'
if __name__ == '__main__':
# Initialize client object.
adwords_client = adwords.AdWordsClient.LoadFromStorage()
main(adwords_client, AD_GROUP_ID, CRITERION_ID)
'displayUrl': 'example.com',
'description1': 'Visit the Red Planet in style.',
'description2': 'Low-gravity fun for all astronauts in orbit',
'headline': 'Luxury Cruise to Mars'
}
}
}]
try:
ad_group_ad_service.mutate(operations)
except suds.WebFault, e:
print 'Validation correctly failed with \'%s\'.' % str(e)
if __name__ == '__main__':
# Initialize client object.
adwords_client = adwords.AdWordsClient.LoadFromStorage()
main(adwords_client, AD_GROUP_ID)