Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Initialize appropriate service.
order_service = client.GetService('OrderService', version='v201511')
# Create query.
values = [{
'key': 'today',
'value': {
'xsi_type': 'TextValue',
'value': datetime.date.today().strftime('%Y-%m-%dT%H:%M:%S')
}
}]
query = ('WHERE status in (\'DRAFT\', \'PENDING_APPROVAL\')'
' AND endDateTime >= :today AND isArchived = FALSE')
# Create a filter statement.
statement = dfp.FilterStatement(query, values)
orders_approved = 0
# Get orders by statement.
while True:
response = order_service.getOrdersByStatement(statement.ToStatement())
if 'results' in response:
# Display results.
for order in response['results']:
print ('Order with id \'%s\', name \'%s\', and status \'%s\' will be '
'approved.' % (order['id'], order['name'], order['status']))
# Perform action.
result = order_service.performOrderAction(
{'xsi_type': 'ApproveOrders'}, statement.ToStatement())
if result and int(result['numChanges']) > 0:
orders_approved += int(result['numChanges'])
statement.offset += dfp.SUGGESTED_PAGE_LIMIT
response = custom_targeting_service.getCustomTargetingKeysByStatement(
targeting_key_statement.ToStatement())
if 'results' in response:
all_keys.extend(response['results'])
targeting_key_statement.offset += dfp.SUGGESTED_PAGE_LIMIT
else:
break
if all_keys:
# Create map of custom targeting key id to custom targeting values.
key_value_map = {}
# Create statement to get all targeting values.
query = ('WHERE customTargetingKeyId IN (%s)'
% ', '.join([str(key['id']) for key in all_keys]))
targeting_value_statement = dfp.FilterStatement(query)
# Get custom targeting values by statement.
while True:
response = custom_targeting_service.getCustomTargetingValuesByStatement(
targeting_value_statement.ToStatement())
if 'results' in response:
for key in all_keys:
for value in response['results']:
if key['id'] == value['customTargetingKeyId']:
if key['id'] not in key_value_map.keys():
key_value_map[key['id']] = []
key_value_map[key['id']].append(value)
targeting_value_statement.offset += dfp.SUGGESTED_PAGE_LIMIT
else:
break
def main(client, reconciliation_report_id):
# Initialize appropriate service.
reconciliation_report_row_service = client.GetService(
'ReconciliationReportRowService', version='v201705')
query = ('WHERE reconciliationReportId = %s AND '
'lineItemId != :lineItemId') % reconciliation_report_id
values = [{
'key': 'lineItemId',
'value': {
'xsi_type': 'NumberValue',
'value': '0'
}
}]
# Create a statement to select reconciliation report rows.
statement = dfp.FilterStatement(query, values)
# Retrieve a small amount of reconciliation report rows at a time, paging
# through until all reconciliation report rows have been retrieved.
while True:
response = (
reconciliation_report_row_service
.getReconciliationReportRowsByStatement(
statement.ToStatement()))
if 'results' in response:
for reconciliation_report_row in response['results']:
# Print out some information for each reconciliation report row.
print('Reconciliation report row with ID "%d", reconciliation source '
'"%s", and reconciled volume "%d" was found.\n' %
(reconciliation_report_row['id'],
reconciliation_report_row['reconciliationSource'],
reconciliation_report_row['reconciledVolume']))
'value': 'PROPOSAL'
}
},
{
'key': 'type',
'value': {
'xsi_type': 'TextValue',
'value': 'WORKFLOW_EXTERNAL_CONDITION_REQUEST'
}
}
]
query = ('WHERE entityId = :entityId and entityType = :entityType '
'and type = :type')
# Create a filter statement.
statement = dfp.FilterStatement(query, values)
workflow_external_condition_requests_triggered = 0
# Get workflow external condition requests by statement.
while True:
response = workflow_request_service.getWorkflowRequestsByStatement(
statement.ToStatement())
if 'results' in response:
# Display results.
for workflow_request in response['results']:
print ('Workflow external condition request with id \'%s\' for %s '
'with id \'%s\' will be triggered.' %
(workflow_request['id'],
workflow_request['entityType'],
workflow_request['entityId']))
# Perform action.
result = workflow_request_service.performWorkflowRequestAction(
def main(client, product_template_id):
# Initialize appropriate service.
product_template_service = client.GetService(
'ProductTemplateService', version='v201511')
# Create a statement to select a single product template by ID.
values = [{
'key': 'id',
'value': {
'xsi_type': 'NumberValue',
'value': product_template_id
}
}]
query = 'WHERE id = :id ORDER BY id ASC'
statement = dfp.FilterStatement(query, values, 1)
# Get product templates by statement.
response = product_template_service.getProductTemplatesByStatement(
statement.ToStatement())
if 'results' in response:
# Update each local product template object by appending a new geo-target.
for product_template in response['results']:
# Create geo-targeting for Canada to append.
location = {
'id': '2124',
'displayName': 'Canada'
}
try:
targeting = product_template['builtInTargeting']
def main(client, proposal_id):
# Initialize appropriate service.
proposal_service = client.GetService('ProposalService', version='v201511')
# Create query.
values = [{
'key': 'proposalId',
'value': {
'xsi_type': 'TextValue',
'value': proposal_id
}
}]
query = 'WHERE id = :proposalId'
# Create a filter statement.
statement = dfp.FilterStatement(query, values)
proposals_approved = 0
# Get proposals by statement.
while True:
response = proposal_service.getProposalsByStatement(statement.ToStatement())
if 'results' in response:
# Display results.
for proposal in response['results']:
print ('Proposal with id \'%s\', name \'%s\', and status \'%s\' will be'
' approved.' % (proposal['id'], proposal['name'],
proposal['status']))
# Perform action.
result = proposal_service.performProposalAction(
{'xsi_type': 'SubmitProposalsForApproval'}, statement.ToStatement())
if result and int(result['numChanges']) > 0:
proposals_approved += int(result['numChanges'])
# Get the custom targeting value ID for the comedy category.
if 'results' in response:
category_custom_targeting_value_id = (response['results']['id'])
# Create a statement to select the active content.
content_values = [
{
'key': 'status',
'value': {
'xsi_type': 'TextValue',
'value': 'ACTIVE'
}
}
]
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
# Create a query to select the active creative wrappers for the given label.
values = [{
'key': 'labelId',
'value': {
'xsi_type': 'NumberValue',
'value': label_id
}
}, {
'key': 'status',
'value': {
'xsi_type': 'TextValue',
'value': 'ACTIVE'
}
}]
query = 'WHERE status = :status AND labelId = :labelId'
statement = dfp.FilterStatement(query, values)
creative_wrappers_deactivated = 0
# Get creative wrappers by statement.
while True:
response = creative_wrapper_service.getCreativeWrappersByStatement(
statement.ToStatement())
if 'results' in response:
# Display results.
for creative_wrapper in response['results']:
print ('Creative wrapper with ID \'%s\' applying to label \'%s\' with '
'status \'%s\' will be deactivated.' %
(creative_wrapper['id'],
creative_wrapper['labelId'],
creative_wrapper['status']))
# Perform action.
def main(client):
# Initialize appropriate service.
user_service = client.GetService('UserService', version='v201511')
# Create a filter statement.
statement = dfp.FilterStatement()
# Get users by statement.
while True:
response = user_service.getUsersByStatement(statement.ToStatement())
if 'results' in response:
# Display results.
for user in response['results']:
print ('User with id \'%s\', email \'%s\', and role \'%s\' was found.'
% (user['id'], user['email'], user['roleName']))
statement.offset += dfp.SUGGESTED_PAGE_LIMIT
else:
break
print '\nNumber of results found: %s' % response['totalResultSetSize']
def main(client):
# Initialize appropriate service.
rate_card_service = client.GetService('RateCardService', version='v201511')
# Create a statement to get all rate cards using USD as currency.
values = [{
'key': 'currencyCode',
'value': {
'xsi_type': 'TextValue',
'value': 'USD'
}
}]
query = 'WHERE currencyCode = :currencyCode'
statement = dfp.FilterStatement(query, values)
# 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']