How to use the starthinker.task.traffic.feed.FieldMap function in starthinker

To help you get started, we’ve selected a few starthinker 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 google / starthinker / starthinker / task / traffic / ad.py View on Github external
def _assignment_matches(self, item, assignment):
    if item.get(FieldMap.AD_ID, None) and assignment.get(FieldMap.AD_ID, None):
      return item.get(FieldMap.AD_ID,
                      None) == assignment.get(FieldMap.AD_ID, None)
    else:
      return item.get(FieldMap.AD_NAME,
                      '1') == assignment.get(FieldMap.AD_NAME, '2')
github google / starthinker / task / traffic / creative_association.py View on Github external
"""Processes a feed item by creating the creative association in DCM.

    Args:
      feed_item: Feed item representing the creative association from the
        Bulkdozer feed.

    Returns:
      The newly created object from DCM.
    """
    if not feed_item.get(FieldMap.CAMPAIGN_CREATIVE_ASSOCIATION_ID, None):
      campaign = self.campaign_dao.get(feed_item, required=True)
      creative = self.creative_dao.get(feed_item, required=True)

      if campaign and creative:
        if campaign:
          feed_item[FieldMap.CAMPAIGN_ID] = campaign['id']
          feed_item[FieldMap.CAMPAIGN_NAME] = campaign['name']

        association = {'creativeId': creative['id']}

        result = self._retry(
            self._service.insert(
                profileId=self.profile_id,
                campaignId=campaign['id'],
                body=association))

        feed_item[FieldMap.CAMPAIGN_CREATIVE_ASSOCIATION_ID] = '%s|%s' % (
            campaign['id'], creative['id'])

        return result

    return None
github google / starthinker / starthinker / task / traffic / run.py View on Github external
def campaigns():
  """Processes campaigns.

  """
  process_feed('campaign_feed', campaign_dao, FieldMap.CAMPAIGN_NAME,
               'Processing campaign')
github google / starthinker / starthinker / task / traffic / video_format.py View on Github external
def translate_transcode_config(self, transcode_configs):
    """Given a transcode config, returns the CM transcodes that match the config.

    Args:
      transcode_config: The transcode configuration feed item.

    Returns:
      All trancode objects from Campaign Manager that match the transcode configuration specified.
    """
    result = []
    REALLY_BIG_INT = 9223372036854775807

    try:
      for video_format in self.get_video_formats():
        for transcode_config in transcode_configs:
          min_width = int(transcode_config.get(FieldMap.TRANSCODE_MIN_WIDTH, 0))
          min_height = int(transcode_config.get(FieldMap.TRANSCODE_MIN_HEIGHT, 0))
          min_bitrate = int(transcode_config.get(FieldMap.TRANSCODE_MIN_BITRATE, 0))

          max_width = int(transcode_config.get(FieldMap.TRANSCODE_MAX_WIDTH, REALLY_BIG_INT))
          max_height = int(transcode_config.get(FieldMap.TRANSCODE_MAX_HEIGHT, REALLY_BIG_INT))
          max_bitrate = int(transcode_config.get(FieldMap.TRANSCODE_MAX_BITRATE, REALLY_BIG_INT))

          file_format = transcode_config.get(FieldMap.TRANSCODE_FORMAT, '')

          # There is one video format entry of id 15 in CM that represents the
          # Source File setting, it has no file type and no resolution, we are
          # using SOURCE_FILE as an artificial handle to allow this transcode
          # configuration to be selected from the sheet
          if file_format == 'SOURCE_FILE':
            if 15 not in result:
              result.append(15)
github google / starthinker / starthinker / task / traffic / ad.py View on Github external
FieldMap.AD_CREATIVE_ROTATION_START_TIME, '')
              else StringExtensions.convertDateStrToDateTimeStr(
                  feed_item.get(FieldMap.AD_CREATIVE_ROTATION_START_TIME,
                                None)))
          assignment[FieldMap.AD_CREATIVE_ROTATION_START_TIME] = startTime
        else:
          startTime = None

        if assignment.get(FieldMap.AD_CREATIVE_ROTATION_END_TIME, ''):
          endTime = (
              assignment.get(FieldMap.AD_CREATIVE_ROTATION_END_TIME, '') if
              'T' in assignment.get(FieldMap.AD_CREATIVE_ROTATION_END_TIME, '')
              else StringExtensions.convertDateStrToDateTimeStr(
                  feed_item.get(FieldMap.AD_CREATIVE_ROTATION_END_TIME, None),
                  '23:59:59'))
          assignment[FieldMap.AD_CREATIVE_ROTATION_END_TIME] = endTime
        else:
          endTime = None

        lp = None
        if assignment.get(FieldMap.AD_LANDING_PAGE_ID, '') != 'CAMPAIGN_DEFAULT':
          lp = self._landing_page_dao.get(assignment, required=True)
        else:
          lp = self._landing_page_dao.get({
              FieldMap.AD_LANDING_PAGE_ID: campaign['defaultLandingPageId']
          }, required=True)

        creative_assignment = {
            'active': True,
            'sequence': sequence,
            'weight': weight,
            'creativeId': assignment.get(FieldMap.CREATIVE_ID, None),
github google / starthinker / starthinker / task / traffic / ad.py View on Github external
False if
                    (assignment.get(FieldMap.AD_LANDING_PAGE_ID, '') or
                     assignment.get(FieldMap.CUSTOM_CLICK_THROUGH_URL, '')) and
                    assignment.get(FieldMap.AD_LANDING_PAGE_ID,
                                   '') != 'CAMPAIGN_DEFAULT' else True,
                'landingPageId':
                    lp.get('id', None) if lp else None,
                'customClickThroughUrl':
                    assignment.get(FieldMap.CUSTOM_CLICK_THROUGH_URL, '')
            }
        }

        if creative.get('exitCustomEvents'):
          creative_assignment['richMediaExitOverrides'] = []

          if assignment.get(FieldMap.AD_LANDING_PAGE_ID, '') or assignment.get(
              FieldMap.CUSTOM_CLICK_THROUGH_URL, ''):
            for exit_custom_event in creative.get('exitCustomEvents', []):
              creative_assignment['richMediaExitOverrides'].append({
                  'exitId': exit_custom_event['id'],
                  'enabled': True,
                  'clickThroughUrl': {
                      'defaultLandingPage':
                          False if
                          (assignment.get(FieldMap.AD_LANDING_PAGE_ID, '') or
                           assignment.get(FieldMap.CUSTOM_CLICK_THROUGH_URL, '')) and
                          assignment.get(FieldMap.AD_LANDING_PAGE_ID,
                                         '') != 'CAMPAIGN_DEFAULT' else True,
                      'landingPageId':
                          lp.get('id', None) if lp else None,
                      'customClickThroughUrl':
                          assignment.get(FieldMap.CUSTOM_CLICK_THROUGH_URL, '')
github google / starthinker / starthinker / task / traffic / creative.py View on Github external
This method transforms all child feed mapped earlier into DCM formatted
    associations within the creative object so it can be pushed to the API.

    Args:
      feed_item: Feed item representing the creative.
      creative: DCM creative object being created or updated.
    """
    third_party_urls = []
    for third_party_url in feed_item.get('third_party_urls', []):
      third_party_url_type = FieldMap.THIRD_PARTY_URL_TYPE_MAP.get(
          third_party_url.get(FieldMap.THIRD_PARTY_URL_TYPE, None))
      if third_party_url_type:
        third_party_urls.append({
            'thirdPartyUrlType': third_party_url_type,
            'url': third_party_url.get(FieldMap.THIRD_PARTY_URL, None)
        })

    if third_party_urls:
      creative['thirdPartyUrls'] = third_party_urls
github google / starthinker / starthinker / task / traffic / run.py View on Github external
"""
  placement_feed = Feed(project.task['auth'], project.task['sheet_id'],
                        'placement_feed', spreadsheet=spreadsheet, timezone=project.task.get('timezone', None))

  pricing_schedule_feed = Feed(project.task['auth'], project.task['sheet_id'],
                               'placement_pricing_schedule_feed', spreadsheet=spreadsheet, timezone=project.task.get('timezone', None))

  transcode_configs_feed = Feed(project.task['auth'], project.task['sheet_id'],
                                'transcode_configs_feed', spreadsheet=spreadsheet, timezone=project.task.get('timezone', None))

  placement_dao.map_placement_transcode_configs(placement_feed.feed,
                                                transcode_configs_feed.feed,
                                                pricing_schedule_feed.feed)

  execute_feed(placement_feed, placement_dao, FieldMap.PLACEMENT_NAME,
               'Processing placement')

  pricing_schedule_feed.update()
github google / starthinker / starthinker / task / traffic / ad.py View on Github external
event_tag = self._event_tag_dao.get(assignment, required=True)
      creative = self._creative_dao.get(assignment, required=True)

      landing_page = None
      if assignment.get(FieldMap.AD_LANDING_PAGE_ID, '') != 'CAMPAIGN_DEFAULT':
        landing_page = self._landing_page_dao.get(assignment, required=True)

      if landing_page:
        assignment[FieldMap.AD_LANDING_PAGE_ID] = landing_page['id']

      if item:
        assignment[FieldMap.AD_ID] = item['id']
        assignment[FieldMap.AD_NAME] = item['name']

      if campaign:
        assignment[FieldMap.CAMPAIGN_ID] = campaign['id']
        assignment[FieldMap.CAMPAIGN_NAME] = campaign['name']

      if placement:
        assignment[FieldMap.PLACEMENT_ID] = placement['id']
        assignment[FieldMap.PLACEMENT_NAME] = placement['name']

      if creative:
        assignment[FieldMap.CREATIVE_ID] = creative['id']
        assignment[FieldMap.CREATIVE_NAME] = creative['name']

      if event_tag:
        assignment[FieldMap.EVENT_TAG_ID] = event_tag['id']
        assignment[FieldMap.EVENT_TAG_NAME] = event_tag['name']
github google / starthinker / starthinker / task / traffic / creative.py View on Github external
def _associate_third_party_urls(self, feed_item, creative):
    """Associate third party urls with the respective creative DCM object.

    This method transforms all child feed mapped earlier into DCM formatted
    associations within the creative object so it can be pushed to the API.

    Args:
      feed_item: Feed item representing the creative.
      creative: DCM creative object being created or updated.
    """
    third_party_urls = []
    for third_party_url in feed_item.get('third_party_urls', []):
      third_party_url_type = FieldMap.THIRD_PARTY_URL_TYPE_MAP.get(
          third_party_url.get(FieldMap.THIRD_PARTY_URL_TYPE, None))
      if third_party_url_type:
        third_party_urls.append({
            'thirdPartyUrlType': third_party_url_type,
            'url': third_party_url.get(FieldMap.THIRD_PARTY_URL, None)
        })

    if third_party_urls:
      creative['thirdPartyUrls'] = third_party_urls