def main(client, advertiser_id):
  # Initialize appropriate service.
  creative_service = client.GetService('CreativeService', version='v201508')

  # Get the image data for the creative.
  image_data = open(os.path.join(os.path.split(__file__)[0], '..', '..', 'data',
                                 'medium_rectangle.jpg'), 'r').read()
  image_data = base64.encodestring(image_data)

  # Create the HTML snippet used in the custom creative.
  html_snippet = ('<a href=\'%s%s\'><img src=\'%s\'/></a><br>Click above for '
                  'great deals!') % ('%%CLICK_URL_UNESC%%', '%%DEST_URL%%',
                                     '%%FILE:IMAGE_ASSET%%')

  # Create custom creative.
  creative = {
      'xsi_type': 'CustomCreative',
      'name': 'Custom Creative #%s' % uuid.uuid4(),
      'advertiserId': advertiser_id,
      'size': {'width': '300', 'height': '250'},
      'destinationUrl': 'http://google.com',
      'customCreativeAssets': [
          {
              'xsi_type': 'CustomCreativeAsset',
              'macroName': 'IMAGE_ASSET',
              'assetByteArray': image_data,
              'fileName': 'image%s.jpg' % uuid.uuid4()
          }
      ],
      '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'], dfp.DfpClassType(creative),
              creative['previewUrl']))
dataset/ETHPy150Open googleads/googleads-python-lib/examples/dfp/v201508/creative_service/create_custom_creative.py/main/original