1- import csv
21import datetime
32import errno
43import gzip
54import http
6- import json
75import csv
86import logging
97import re
@@ -56,7 +54,7 @@ def _fetch_managed_customer_page(self):
5654
5755 """
5856 service = self .GetService (service_name = 'ManagedCustomerService' )
59- return service .get ({'fields' : ['CustomerId' , 'Name' , 'CanManageClients' , 'AccountLabels' ]})
57+ return service .get ({'fields' : ['CustomerId' , 'Name' , 'CanManageClients' , 'AccountLabels' , 'CurrencyCode' ]})
6058
6159 def _fetch_client_customers (self ):
6260 """Fetches the client customers, including their names and account labels, from
@@ -78,7 +76,8 @@ def _fetch_client_customers(self):
7876 account_labels = [x .name for x in managed_customer .accountLabels ]
7977 client_customers [managed_customer .customerId ] = {
8078 'Name' : managed_customer .name ,
81- 'Labels' : account_labels }
79+ 'Labels' : account_labels ,
80+ 'Currency Code' : managed_customer .currencyCode }
8281 return client_customers
8382
8483
@@ -209,7 +208,7 @@ def download_account_structure(api_client: AdWordsApiClient):
209208 tmp_filepath = Path (tmp_dir , filename )
210209 with gzip .open (str (tmp_filepath ), 'wt' ) as tmp_campaign_structure_file :
211210 header = ['Ad Id' , 'Ad' , 'Ad Group Id' , 'Ad Group' , 'Campaign Id' ,
212- 'Campaign' , 'Customer Id' , 'Customer Name' , 'Attributes' ]
211+ 'Campaign' , 'Customer Id' , 'Customer Name' , 'Attributes' , 'Currency Code' ]
213212 writer = csv .writer (tmp_campaign_structure_file , delimiter = "\t " )
214213 writer .writerow (header )
215214 for client_customer_id , client_customer in api_client .client_customers .items ():
@@ -224,7 +223,7 @@ def download_account_structure(api_client: AdWordsApiClient):
224223 for ad_id , ad_data_dict in ad_data .items ():
225224 campaign_id = ad_data_dict ['Campaign ID' ]
226225 ad_group_id = ad_data_dict ['Ad group ID' ]
227-
226+ currency_code = client_customer [ 'Currency Code' ]
228227 attributes = {** client_customer_attributes ,
229228 ** campaign_attributes .get (campaign_id , {}),
230229 ** ad_group_attributes .get (ad_group_id , {}),
@@ -238,7 +237,9 @@ def download_account_structure(api_client: AdWordsApiClient):
238237 ad_data_dict ['Campaign' ],
239238 str (client_customer_id ),
240239 client_customer_name ,
241- json .dumps (attributes )]
240+ json .dumps (attributes ),
241+ currency_code
242+ ]
242243
243244 writer .writerow (ad )
244245
0 commit comments