def main(client, campaign_id):
  # Initialize appropriate services.
  campaign_extension_setting_service = client.GetService(
      'CampaignExtensionSettingService', version='v201509')
  customer_service = client.GetService('CustomerService', version='v201509')

  customer_tz = timezone(customer_service.get()['dateTimeZone'])
  time_fmt = '%s %s' % ('%Y%m%d %H%M%S', customer_tz)

  # Create the sitelinks
  sitelink1 = {
      'xsi_type': 'SitelinkFeedItem',
      'sitelinkText': 'Store Hours',
      'sitelinkFinalUrls': {'urls': ['http://www.example.com/storehours']}
  }

  # Show the Thanksgiving specials link only from 20 - 27 Nov.
  sitelink2 = {
      'xsi_type': 'SitelinkFeedItem',
      'sitelinkText': 'Thanksgiving Specials',
      'sitelinkFinalUrls': {'urls': ['http://www.example.com/thanksgiving']},
      # The time zone of the start and end date/times must match the time zone
      # of the customer.
      'startTime': datetime(datetime.now().year, 11, 20, 0, 0, 0, 0,
                            customer_tz).strftime(time_fmt),
      'endTime': datetime(datetime.now().year, 11, 27, 23, 59, 59, 59,
                          customer_tz).strftime(time_fmt)
  }

  # Show the wifi details primarily for high end mobile users.
  sitelink3 = {
      'xsi_type': 'SitelinkFeedItem',
      'sitelinkText': 'Wifi Available',
      'sitelinkFinalUrls': {'urls': ['http://www.example.com/mobile/wifi']},
      # See https://developers.google.com/adwords/api/docs/appendix/platforms
      # for device criteria IDs.
      'devicePreference': {'devicePreference': '30001'}
  }

  # Show the happy hours link only during Mon - Fri 6PM to 9PM.
  sitelink4 = {
      'xsi_type': 'SitelinkFeedItem',
      'sitelinkText': 'Happy hours',
      'sitelinkFinalUrls': {'urls': ['http://www.example.com/happyhours']},
      'scheduling': {
          'feedItemSchedules': [
              {
                  'dayOfWeek': day,
                  'startHour': '18',
                  'startMinute': 'ZERO',
                  'endHour': '21',
                  'endMinute': 'ZERO'
              } for day in ['MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY',
                            'FRIDAY']
          ]
      }
  }

  # Create your Campaign Extension Settings. This associates the sitelinks
  # to your campaign.
  campaign_extension_setting = {
      'campaignId': campaign_id,
      'extensionType': 'SITELINK',
      'extensionSetting': {
          'extensions': [sitelink1, sitelink2, sitelink3, sitelink4]
      }
  }

  operation = {
      'operator': 'ADD',
      'operand': campaign_extension_setting
  }

  # Add the extensions.
  response = campaign_extension_setting_service.mutate([operation])

  if 'value' in response:
    print ('Extension setting with type "%s" was added to campaignId "%d".' %
           (response['value'][0]['extensionType'],
            response['value'][0]['campaignId']))
  else:
    raise errors.GoogleAdsError('No extension settings were added.')
dataset/ETHPy150Open googleads/googleads-python-lib/examples/adwords/v201509/extensions/add_site_links.py/main/original