Gets the Feed Mapping for a given Feed.

  Args:
    client: an AdWordsClient instance.
    feed: the Feed we are retrieving the Feed Mapping for.
    placeholder_type: the Placeholder Type we are looking for.
  Returns:
    A dictionary containing the Feed Mapping.

def GetFeedMapping(client, feed, placeholder_type):
  """Gets the Feed Mapping for a given Feed.

  Args:
    client: an AdWordsClient instance.
    feed: the Feed we are retrieving the Feed Mapping for.
    placeholder_type: the Placeholder Type we are looking for.
  Returns:
    A dictionary containing the Feed Mapping.
  """
  feed_mapping_service = client.GetService('FeedMappingService', 'v201809')

  attribute_mappings = {}
  more_pages = True

  selector = {
      'fields': ['FeedMappingId', 'AttributeFieldMappings'],
      'predicates': [
          {
              'field': 'FeedId',
              'operator': 'EQUALS',
              'values': [feed['id']]
          },
          {
              'field': 'PlaceholderType',
              'operator': 'EQUALS',
              'values': [placeholder_type]
          }
      ],
      'paging': {
          'startIndex': 0,
          'numberResults': PAGE_SIZE
      }
  }

  while more_pages:
    page = feed_mapping_service.get(selector)

    if 'entries' in page:
      # Normally, a feed attribute is mapped only to one field. However, you may
      # map it to more than one field if needed.
      for feed_mapping in page['entries']:
        for attribute_mapping in feed_mapping['attributeFieldMappings']:
          # Since attribute mappings can have multiple values for each key,
          # we use a list to store the values.
          if attribute_mapping['feedAttributeId'] in attribute_mappings:
            attribute_mappings[attribute_mapping['feedAttributeId']].append(
                attribute_mapping['fieldId'])
          else:
            attribute_mappings[attribute_mapping['feedAttributeId']] = [
                attribute_mapping['fieldId']]

    selector['paging']['startIndex'] += PAGE_SIZE
    more_pages = selector['paging']['startIndex'] < int(page['totalNumEntries'])

  return attribute_mappings