How to use the googleads.dfp.DfpClassType function in googleads

To help you get started, we’ve selected a few googleads examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github googleads / googleads-python-lib / examples / dfp / v201802 / premium_rate_service / get_all_premium_rates.py View on Github external
'PremiumRateService', version='v201802')

  # Create a statement to select premium rates.
  statement = dfp.StatementBuilder()

  # Retrieve a small amount of premium rates at a time, paging
  # through until all premium rates have been retrieved.
  while True:
    response = premium_rate_service.getPremiumRatesByStatement(
        statement.ToStatement())
    if 'results' in response and len(response['results']):
      for premium_rate in response['results']:
        # Print out some information for each premium rate.
        print('Premium rate with ID "%d", premium feature "%s", and rate card '
              'id "%d" was found.\n' % (premium_rate['id'],
                                        dfp.DfpClassType(premium_rate),
                                        premium_rate['rateCardId']))
      statement.offset += statement.limit
    else:
      break

  print '\nNumber of results found: %s' % response['totalResultSetSize']
github googleads / googleads-python-lib / examples / dfp / v201805 / premium_rate_service / create_premium_rates.py View on Github external
# for both CPM and CPC rate types.
  premium_rate = {
      'rateCardId': rate_card_id,
      'pricingMethod': 'ANY_VALUE',
      'premiumFeature': ad_unit_premium_feature,
      'premiumRateValues': [cpc_premium_rate_value, cpm_premium_rate_value]
  }

  # Add premium_rates.
  premium_rates = premium_rate_service.createPremiumRates([premium_rate])

  # Display results.
  for premium_rate in premium_rates:
    print ('A premium rate for "%s" was added to the rate card with ID'
           ' of "%s".\n'
           % (dfp.DfpClassType(premium_rate['premiumFeature']),
              premium_rate['id']))
github googleads / googleads-python-lib / examples / dfp / v201705 / publisher_query_language_service / get_recent_changes.py View on Github external
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 = dfp.DfpClassType(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 '-'
github googleads / googleads-python-lib / examples / dfp / v201802 / creative_service / copy_image_creatives.py View on Github external
# 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'],
                                      dfp.DfpClassType(result),
                                      result['previewUrl']))
github googleads / googleads-python-lib / examples / dfp / v201802 / base_rate_service / get_base_rates_for_rate_card.py View on Github external
# Create a statement to select base rates.
  statement = (dfp.StatementBuilder()
               .Where('rateCardId = :rateCardId')
               .WithBindVariable('rateCardId', rate_card_id))

  # Retrieve a small amount of base rates at a time, paging
  # through until all base rates have been retrieved.
  while True:
    response = base_rate_service.getBaseRatesByStatement(statement.ToStatement(
    ))
    if 'results' in response and len(response['results']):
      for base_rate in response['results']:
        # Print out some information for each base rate.
        print('Base rate with ID "%d", type "%s", and rate card ID "%d" was '
              'found.\n' %
              (base_rate['id'], dfp.DfpClassType(base_rate),
               base_rate['rateCardId']))
      statement.offset += statement.limit
    else:
      break

  print '\nNumber of results found: %s' % response['totalResultSetSize']
github googleads / googleads-python-lib / examples / dfp / v201511 / base_rate_service / get_base_rates_for_a_rate_card.py View on Github external
}
  }]
  query = 'where rateCardId = :rateCardId ORDER BY id ASC'
  statement = dfp.FilterStatement(query, values)

  # Get base rates by statement.
  while True:
    response = base_rate_service.getBaseRatesByStatement(
        statement.ToStatement())
    if 'results' in response:
      # Display results.
      for base_rate in response['results']:
        print ('Base rate with ID \'%s\' and type \'%s\' belonging to '
               'rate card ID \'%s\' was found.' % (
                   base_rate['id'],
                   dfp.DfpClassType(base_rate),
                   base_rate['rateCardId']))
      statement.offset += dfp.SUGGESTED_PAGE_LIMIT
    else:
      break

  print '\nNumber of results found: %s' % response['totalResultSetSize']
github googleads / googleads-python-lib / examples / dfp / v201805 / publisher_query_language_service / get_recent_changes.py View on Github external
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 = dfp.DfpClassType(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 '-'
github googleads / googleads-python-lib / examples / dfp / v201802 / creative_service / create_creative_from_template.py View on Github external
},
          {
              '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']))
github googleads / googleads-python-lib / examples / dfp / v201805 / base_rate_service / get_all_base_rates.py View on Github external
# Initialize appropriate service.
  base_rate_service = client.GetService('BaseRateService', version='v201805')

  # Create a statement to select base rates.
  statement = dfp.StatementBuilder()

  # Retrieve a small amount of base rates at a time, paging
  # through until all base rates have been retrieved.
  while True:
    response = base_rate_service.getBaseRatesByStatement(statement.ToStatement(
    ))
    if 'results' in response and len(response['results']):
      for base_rate in response['results']:
        # Print out some information for each base rate.
        print('Base rate with ID "%d", type "%s", and rate card ID "%d" was '
              'found.\n' % (base_rate['id'], dfp.DfpClassType(base_rate),
                            base_rate['rateCardId']))
      statement.offset += statement.limit
    else:
      break

  print '\nNumber of results found: %s' % response['totalResultSetSize']
github googleads / googleads-python-lib / examples / dfp / v201805 / base_rate_service / update_base_rates.py View on Github external
updated_base_rates = []
    for base_rate in response['results']:
      base_rate['rate'] = new_rate
      updated_base_rates.append(base_rate)

    # Update base rates remotely.
    base_rates = base_rate_service.updateBaseRates(updated_base_rates)

    # Display results.
    if base_rates:
      for base_rate in base_rates:
        print ('Base rate with ID "%s" and type "%s" belonging to '
               'rate card ID "%s" was updated.' % (
                   base_rate['id'],
                   dfp.DfpClassType(base_rate),
                   base_rate['rateCardId']))
    else:
      print 'No base rates were updated.'
  else:
    print 'No base rates found to update.'