def main(client, product_template_id):
  # Initialize appropriate service.
  product_template_service = client.GetService(
      'ProductTemplateService', version='v201602')

  # 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']

        if 'geoTargeting' in targeting:
          geo_targeting = targeting['geoTargeting']

          if 'targetedLocations' in geo_targeting:
            geo_targeting['targetedLocations'].append(location)
          else:
            geo_targeting['targetedLocations'] = [location]
        else:
          targeting['geoTargeting'] = {
              'targetedLocations': [location]
          }
      except KeyError:
        product_template['builtInTargeting'] = {
            'geoTargeting': {
                'targetedLocations': [location]
            }
        }

      # Update products remotely.
      product_templates = product_template_service.updateProductTemplates(
          [product_template])

    # Display results.
    if product_templates:
      for product_template in product_templates:
        print ('Product template with id \'%s\' and name \'%s\' was '
               'updated.' % (product_template['id'], product_template['name']))
    else:
      print 'No product templates were updated.'
  else:
    print 'No product templates found to update.'
dataset/ETHPy150Open googleads/googleads-python-lib/examples/dfp/v201602/product_template_service/update_product_templates.py/main/original