Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Get the creative.
query_result = creative_service.getCreativesByStatement(
statement.ToStatement())
image_creative = query_result['results'][0]
# Build the new creative, set id to None to create a copy.
image_creative['id'] = None
image_creative['name'] = 'Copy of %s' % image_creative['name']
result = creative_service.createCreatives([image_creative])[0]
print ('A creative with ID %d, name "%s", and type "%s" was created and '
'can be previewed at: %s' % (result['id'],
result['name'],
ad_manager.AdManagerClassType(result),
result['previewUrl']))
if (old_custom_field_value['customFieldId'] !=
custom_field_value['customFieldId']
and old_custom_field_value['customFieldId'] !=
drop_down_custom_field_value['customFieldId']):
custom_field_values.append(old_custom_field_value)
line_item['customFieldValues'] = custom_field_values
# Update the line item on the server.
line_items = line_item_service.updateLineItems([line_item])
# Display results.
for line_item in line_items:
custom_field_value_strings = []
for value in line_item['customFieldValues']:
if ad_manager.AdManagerClassType(value) == 'CustomFieldValue':
custom_field_value_string = (
'{ID: "%s", value: "%s"}'
% (value['customFieldId'], value['value']['value']))
elif ad_manager.AdManagerClassType(value) == 'DropDownCustomFieldValue':
custom_field_value_string = (
'{ID: "%s", custom field option ID: "%s"}'
% (value['customFieldId'], value['customFieldOptionId']))
custom_field_value_strings.append(custom_field_value_string)
print('Line item with ID "%s" set with custom field values %s.'
% (line_item['id'], ','.join(custom_field_value_strings)))
else:
print('Line item or custom field not found.')
custom_field_values.append(old_custom_field_value)
line_item['customFieldValues'] = custom_field_values
# Update the line item on the server.
line_items = line_item_service.updateLineItems([line_item])
# Display results.
for line_item in line_items:
custom_field_value_strings = []
for value in line_item['customFieldValues']:
if ad_manager.AdManagerClassType(value) == 'CustomFieldValue':
custom_field_value_string = (
'{ID: "%s", value: "%s"}'
% (value['customFieldId'], value['value']['value']))
elif ad_manager.AdManagerClassType(value) == 'DropDownCustomFieldValue':
custom_field_value_string = (
'{ID: "%s", custom field option ID: "%s"}'
% (value['customFieldId'], value['customFieldOptionId']))
custom_field_value_strings.append(custom_field_value_string)
print('Line item with ID "%s" set with custom field values %s.'
% (line_item['id'], ','.join(custom_field_value_strings)))
else:
print('Line item or custom field not found.')
Returns:
str a CSV writer friendly value formatted by Value.Type.
"""
if 'value' in pql_value:
field = pql_value['value']
elif 'values' in pql_value:
field = pql_value['values']
else:
field = None
if field:
if isinstance(field, list):
return ','.join(['"%s"' % str(ConvertValueForCsv(single_field))
for single_field in field])
else:
class_type = ad_manager.AdManagerClassType(pql_value)
if class_type == 'TextValue':
return field.replace('"', '""').encode('UTF8')
elif class_type == 'NumberValue':
return float(field) if '.' in field else int(field)
elif class_type == 'DateTimeValue':
return ConvertDateTimeToOffset(field)
elif class_type == 'DateValue':
return date(int(field['date']['year']),
int(field['date']['month']),
int(field['date']['day'])).isoformat()
else:
return field
else:
return '-'
if (old_custom_field_value['customFieldId'] !=
custom_field_value['customFieldId']
and old_custom_field_value['customFieldId'] !=
drop_down_custom_field_value['customFieldId']):
custom_field_values.append(old_custom_field_value)
line_item['customFieldValues'] = custom_field_values
# Update the line item on the server.
line_items = line_item_service.updateLineItems([line_item])
# Display results.
for line_item in line_items:
custom_field_value_strings = []
for value in line_item['customFieldValues']:
if ad_manager.AdManagerClassType(value) == 'CustomFieldValue':
custom_field_value_string = (
'{ID: "%s", value: "%s"}'
% (value['customFieldId'], value['value']['value']))
elif ad_manager.AdManagerClassType(value) == 'DropDownCustomFieldValue':
custom_field_value_string = (
'{ID: "%s", custom field option ID: "%s"}'
% (value['customFieldId'], value['customFieldOptionId']))
custom_field_value_strings.append(custom_field_value_string)
print('Line item with ID "%s" set with custom field values %s.'
% (line_item['id'], ','.join(custom_field_value_strings)))
else:
print('Line item or custom field not found.')
}
}
],
'htmlSnippet': html_snippet
}
# Call service to create the creative.
creatives = creative_service.createCreatives([creative])
# Display results.
if creatives:
creative = creatives[0]
print('Template creative with id "%s", name "%s", and type "%s" was '
'created and can be previewed at %s.'
% (creative['id'], creative['name'],
ad_manager.AdManagerClassType(creative), creative['previewUrl']))
'destinationUrl': 'http://google.com',
'size': size,
'primaryImageAsset': creative_asset
}
creatives.append(creative)
# Add creatives.
creatives = creative_service.createCreatives(creatives)
# Display results.
for creative in creatives:
print('Image creative with id "%s", name "%s", and type "%s" was '
'created and can be previewed at %s.'
% (creative['id'], creative['name'],
ad_manager.AdManagerClassType(creative), creative['previewUrl']))
Returns:
str a CSV writer friendly value formatted by Value.Type.
"""
if 'value' in pql_value:
field = pql_value['value']
elif 'values' in pql_value:
field = pql_value['values']
else:
field = None
if field:
if isinstance(field, list):
return ','.join(['"%s"' % str(ConvertValueForCsv(single_field))
for single_field in field])
else:
class_type = ad_manager.AdManagerClassType(pql_value)
if class_type == 'TextValue':
return field.replace('"', '""').encode('UTF8')
elif class_type == 'NumberValue':
return float(field) if '.' in field else int(field)
elif class_type == 'DateTimeValue':
return ConvertDateTimeToOffset(field)
elif class_type == 'DateValue':
return date(int(field['date']['year']),
int(field['date']['month']),
int(field['date']['day'])).isoformat()
else:
return field
else:
return '-'