Builds the operations adding a Keyword Criterion to each AdGroup.

  Args:
    adgroup_id: an integer identifying an AdGroup to associate the keywords
      with.

  Returns:
    a list containing the operations that will create a new Keyword Criterion
    associated with each provided AdGroup.

def BuildAdGroupCriterionOperations(adgroup_id):
  """Builds the operations adding a Keyword Criterion to each AdGroup.

  Args:
    adgroup_id: an integer identifying an AdGroup to associate the keywords
      with.

  Returns:
    a list containing the operations that will create a new Keyword Criterion
    associated with each provided AdGroup.
  """
  criterion_operations = [
      {
          # You must specify the xsi_type of operations run by the
          # BatchJobService.
          'xsi_type': 'AdGroupCriterionOperation',
          'operand': {
              'xsi_type': 'BiddableAdGroupCriterion',
              'adGroupId': adgroup_id,
              'criterion': {
                  'xsi_type': 'Keyword',
                  # Make 10% of keywords invalid to demonstrate error handling.
                  'text': 'mars%s%s' % (uuid.uuid4(),
                                        '!!!' if i % 10 == 0 else ''),
                  'matchType': 'BROAD'
              }
          },
          'operator': 'ADD'
      }
      for i in range(KEYWORD_COUNT)]

  return criterion_operations