#NEWLINE# def main( client ) : #NEWLINE# #INDENT# adwords_user_list_service = client . GetService ( 'AdwordsUserListService' , version = 'v201601' ) #NEWLINE# checkout_rule_item = { #NEWLINE# #INDENT# 'StringRuleItem' : { #NEWLINE# #INDENT# 'key' : { #NEWLINE# #INDENT# 'name' : 'ecomm_pagetype' , #NEWLINE# #UNINDENT# } , #NEWLINE# 'op' : 'EQUALS' , #NEWLINE# 'value' : 'checkout' , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# cart_size_rule_item = { #NEWLINE# #INDENT# 'NumberRuleItem' : { #NEWLINE# #INDENT# 'key' : { #NEWLINE# #INDENT# 'name' : 'cartsize' , #NEWLINE# #UNINDENT# } , #NEWLINE# 'op' : 'GREATER_THAN' , #NEWLINE# 'value' : '1.0' , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# checkout_multiple_item_group = { #NEWLINE# #INDENT# 'items' : [ checkout_rule_item , cart_size_rule_item ] , #NEWLINE# #UNINDENT# } #NEWLINE# today = date . today ( ) #NEWLINE# start_date_rule_item = { #NEWLINE# #INDENT# 'DateRuleItem' : { #NEWLINE# #INDENT# 'key' : { #NEWLINE# #INDENT# 'name' : 'checkoutdate' , #NEWLINE# #UNINDENT# } , #NEWLINE# 'op' : 'AFTER' , #NEWLINE# 'value' : today . strftime ( '%Y%m%d' ) , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# three_months_later = AddMonths ( today , 3 ) #NEWLINE# three_months_later_rule_item = { #NEWLINE# #INDENT# 'DateRuleItem' : { #NEWLINE# #INDENT# 'key' : { #NEWLINE# #INDENT# 'name' : 'checkoutdate' , #NEWLINE# #UNINDENT# } , #NEWLINE# 'op' : 'BEFORE' , #NEWLINE# 'value' : three_months_later . strftime ( '%Y%m%d' ) , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# checked_out_date_range_item_group = { #NEWLINE# #INDENT# 'items' : [ start_date_rule_item , three_months_later_rule_item ] , #NEWLINE# #UNINDENT# } #NEWLINE# rule = { #NEWLINE# #INDENT# 'groups' : [ checkout_multiple_item_group , checked_out_date_range_item_group ] , #NEWLINE# #UNINDENT# } #NEWLINE# expression_user_list = { #NEWLINE# #INDENT# 'xsi_type' : 'ExpressionRuleUserList' , #NEWLINE# 'name' : ( 'Expression-based user list created at %s' % datetime . today ( ) . strftime ( '%Y%m%d %H:%M:%S' ) ) , #NEWLINE# 'description' : 'Users who checked out in three month window OR visited the checkout page with more than one item in their cart.' , #NEWLINE# 'rule' : rule , #NEWLINE# #UNINDENT# } #NEWLINE# end_date = AddMonths ( today , 6 ) #NEWLINE# date_user_list = { #NEWLINE# #INDENT# 'xsi_type' : 'DateSpecificRuleUserList' , #NEWLINE# 'name' : ( 'Date rule user list created at %s' % datetime . today ( ) . strftime ( '%Y%m%d %H:%M:%S' ) ) , #NEWLINE# 'description' : ( 'Users who visited the site between %s and %s and checked out in three month window OR visited the checkout page with more than one item in their cart.' % ( today . strftime ( '%Y%m%d' ) , end_date . strftime ( '%Y%m%d' ) ) ) , #NEWLINE# 'rule' : rule , #NEWLINE# 'startDate' : today . strftime ( '%Y%m%d' ) , #NEWLINE# 'endDate' : end_date . strftime ( '%Y%m%d' ) , #NEWLINE# #UNINDENT# } #NEWLINE# operations = [ { #NEWLINE# #INDENT# 'operand' : user_list , #NEWLINE# 'operator' : 'ADD' , #NEWLINE# #UNINDENT# } for user_list in [ expression_user_list , date_user_list ] ] #NEWLINE# user_lists = adwords_user_list_service . mutate ( operations ) #NEWLINE# for user_list in user_lists [ 'value' ] : #NEWLINE# #INDENT# print ( ( 'User list added with ID %d, name "%s", status "%s", list type "%s", accountUserListStatus "%s", description "%s".' % ( user_list [ 'id' ] , user_list [ 'name' ] , user_list [ 'status' ] , user_list [ 'listType' ] , user_list [ 'accountUserListStatus' ] , user_list [ 'description' ] ) ) )