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

  # Use the image banner with optional third party tracking template.
  creative_template_id = '10000680'

  image_data = open(os.path.join(os.path.split(__file__)[0], '..', '..', 'data',
                                 'medium_rectangle.jpg'), 'r').read()
  image_data = base64.encodestring(image_data)
  # Create creative from templates.
  creative = {
      'xsi_type': 'TemplateCreative',
      'name': 'Template Creative #%s' % uuid.uuid4(),
      'advertiserId': advertiser_id,
      'size': {'width': '300', 'height': '250'},
      'creativeTemplateId': creative_template_id,
      'creativeTemplateVariableValues': [
          {
              'xsi_type': 'AssetCreativeTemplateVariableValue',
              'uniqueName': 'Imagefile',
              'assetByteArray': image_data,
              'fileName': 'image%s.jpg' % uuid.uuid4()
          },
          {
              'xsi_type': 'LongCreativeTemplateVariableValue',
              'uniqueName': 'Imagewidth',
              'value': '300'
          },
          {
              'xsi_type': 'LongCreativeTemplateVariableValue',
              'uniqueName': 'Imageheight',
              'value': '250'
          },
          {
              'xsi_type': 'UrlCreativeTemplateVariableValue',
              'uniqueName': 'ClickthroughURL',
              'value': 'www.google.com'
          },
          {
              'xsi_type': 'StringCreativeTemplateVariableValue',
              'uniqueName': 'Targetwindow',
              'value': '_blank'
          }
      ]
  }

  # Call service to create the creative.
  creative = creative_service.createCreatives([creative])[0]

  # Display results.
  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/v201505/creative_service/create_creative_from_template.py/main/original