Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.WithBindVariable('orderId', long(order_id)))
# Collect all line item custom field IDs for an order.
custom_field_ids = set()
# Get users by statement.
while True:
response = line_item_service.getLineItemsByStatement(
statement.ToStatement())
if 'results' in response:
# Get custom field IDs from the line items of an order.
for line_item in response['results']:
if 'customFieldValues' in line_item:
for custom_field_value in line_item['customFieldValues']:
custom_field_ids.add(custom_field_value['customFieldId'])
statement.offset += dfp.SUGGESTED_PAGE_LIMIT
else:
break
# Modify statement for reports
statement.limit = None
statement.offset = None
statement.Where('ORDER_ID = :orderId')
# Create report job.
report_job = {
'reportQuery': {
'dimensions': ['LINE_ITEM_ID', 'LINE_ITEM_NAME'],
'statement': statement.ToStatement(),
'columns': ['AD_SERVER_IMPRESSIONS'],
'dateRangeType': 'LAST_MONTH',
'customFieldIds': list(custom_field_ids)
if 'results' in response:
# Separate the ad units by size.
for ad_unit in response['results']:
if 'adUnitSizes' in ad_unit:
for ad_unit_size in ad_unit['adUnitSizes']:
size = ad_unit_size['size']
if size['width'] == '300' and size['height'] == '250':
medium_rectangle_ad_unit_placement['targetedAdUnitIds'].append(
ad_unit['id'])
elif size['width'] == '120' and size['height'] == '600':
skyscraper_ad_unit_placement['targetedAdUnitIds'].append(
ad_unit['id'])
elif size['width'] == '468' and size['height'] == '60':
banner_ad_unit_placement['targetedAdUnitIds'].append(
ad_unit['id'])
statement.offset += dfp.SUGGESTED_PAGE_LIMIT
else:
break
# Only create placements with one or more ad unit.
if medium_rectangle_ad_unit_placement['targetedAdUnitIds']:
placement_list.append(medium_rectangle_ad_unit_placement)
if skyscraper_ad_unit_placement['targetedAdUnitIds']:
placement_list.append(skyscraper_ad_unit_placement)
if banner_ad_unit_placement['targetedAdUnitIds']:
placement_list.append(banner_ad_unit_placement)
# Add placements.
placements = placement_service.createPlacements(placement_list)
# Create a statement to select workflow requests.
statement = dfp.FilterStatement(query, values)
# Retrieve a small amount of workflow requests at a time, paging
# through until all workflow requests have been retrieved.
while True:
response = workflow_request_service.getWorkflowRequestsByStatement(
statement.ToStatement())
if 'results' in response:
for workflow_request in response['results']:
# Print out some information for each workflow request.
print('Workflow request with ID "%d", entity type "%s", and entity ID '
'"%d" was found.\n' % (workflow_request['id'],
workflow_request['entityType'],
workflow_request['entityId']))
statement.offset += dfp.SUGGESTED_PAGE_LIMIT
else:
break
print '\nNumber of results found: %s' % response['totalResultSetSize']
}]
query = 'WHERE entityType = :entityType'
# Create a filter statement.
statement = dfp.FilterStatement(query, values)
# Get custom fields by statement.
while True:
response = custom_field_service.getCustomFieldsByStatement(
statement.ToStatement())
if 'results' in response:
# Display results.
for custom_field in response['results']:
print ('Custom field with ID \'%s\' and name \'%s\' was found.'
% (custom_field['id'], custom_field['name']))
statement.offset += dfp.SUGGESTED_PAGE_LIMIT
else:
break
print '\nNumber of results found: %s' % response['totalResultSetSize']
]
content_query = 'WHERE status = :status'
content_statement = dfp.FilterStatement(content_query, content_values)
while True:
# Get the content by statement and custom targeting value.
response = content_service.getContentByStatementAndCustomTargetingValue(
content_statement.ToStatement(),
category_custom_targeting_value_id)
if 'results' in response:
# Display results.
for content_item in response['results']:
print ('Content with id \'%s\', name \'%s\', and status \'%s\' was '
'found.' % (content_item['id'], content_item['name'],
content_item['status']))
content_statement.offset += dfp.SUGGESTED_PAGE_LIMIT
else:
break
print '\nNumber of results found: %s' % response['totalResultSetSize']
]
content_query = 'WHERE status = :status'
content_statement = dfp.FilterStatement(content_query, content_values)
while True:
# Get the content by statement and custom targeting value.
response = content_service.getContentByStatementAndCustomTargetingValue(
content_statement.ToStatement(),
category_custom_targeting_value_id)
if 'results' in response:
# Display results.
for content_item in response['results']:
print ('Content with id \'%s\', name \'%s\', and status \'%s\' was '
'found.' % (content_item['id'], content_item['name'],
content_item['status']))
content_statement.offset += dfp.SUGGESTED_PAGE_LIMIT
else:
break
print '\nNumber of results found: %s' % response['totalResultSetSize']
'value': product_template_id
}},
]
# Create a statement to select products.
statement = dfp.FilterStatement(query, values)
# Retrieve a small amount of products at a time, paging
# through until all products have been retrieved.
while True:
response = product_service.getProductsByStatement(statement.ToStatement())
if 'results' in response:
for product in response['results']:
# Print out some information for each product.
print('Product with ID "%d" and name "%s" was found.\n' %
(product['id'], product['name']))
statement.offset += dfp.SUGGESTED_PAGE_LIMIT
else:
break
print '\nNumber of results found: %s' % response['totalResultSetSize']
def main(client):
# Initialize appropriate service.
inventory_service = client.GetService('InventoryService', version='v201605')
statement = dfp.FilterStatement()
all_ad_units = []
# Get ad units by statement.
while True:
response = inventory_service.getAdUnitsByStatement(
statement.ToStatement())
if 'results' in response:
all_ad_units.extend(response['results'])
statement.offset += dfp.SUGGESTED_PAGE_LIMIT
else:
break
# Find the root ad unit. root_ad_unit can also be set to child unit to only
# build and display a portion of the tree.
query = 'WHERE parentId IS NULL'
root_statement = dfp.FilterStatement(query)
response = inventory_service.getAdUnitsByStatement(
root_statement.ToStatement())
root_ad_unit = response['results'][0]
if root_ad_unit:
BuildAndDisplayAdUnitTree(root_ad_unit, all_ad_units)
else:
print 'Could not build tree. No root ad unit found.'
# Get rate cards by statement.
while True:
response = exchange_rate_service.getExchangeRatesByStatement(
statement.ToStatement())
if 'results' in response:
# Display results.
for exchange_rate in response['results']:
print ('Exchange rate with id \'%s,\' currency code \'%s,\' '
'direction \'%s,\' and exchange rate \'%.2f\' '
'was found.' % (exchange_rate['id'],
exchange_rate['currencyCode'],
exchange_rate['direction'],
(float(exchange_rate['exchangeRate']) /
10000000000)))
statement.offset += dfp.SUGGESTED_PAGE_LIMIT
else:
break
print '\nNumber of results found: %s' % response['totalResultSetSize']
rate_card_service = client.GetService('RateCardService', version='v201511')
# Create a filter statement.
statement = dfp.FilterStatement('ORDER BY id ASC')
# Get rate cards by statement.
while True:
response = rate_card_service.getRateCardsByStatement(
statement.ToStatement())
if 'results' in response:
# Display results.
for rate_card in response['results']:
print ('Rate card with id \'%s,\' name \'%s,\' and currency \'%s\' '
'was found.' % (rate_card['id'], rate_card['name'],
rate_card['currencyCode']))
statement.offset += dfp.SUGGESTED_PAGE_LIMIT
else:
break
print '\nNumber of results found: %s' % response['totalResultSetSize']