@@ -620,6 +620,12 @@ def normalize_and_hash(s: str, remove_all_whitespace: bool) -> str:
620620
621621
622622if __name__ == "__main__" :
623+ # GoogleAdsClient will read the google-ads.yaml configuration file in the
624+ # home directory if none is specified.
625+ googleads_client : GoogleAdsClient = GoogleAdsClient .load_from_storage (
626+ version = "v20"
627+ )
628+
623629 parser : argparse .ArgumentParser = argparse .ArgumentParser (
624630 description = "Adds a customer match user list for specified customer."
625631 )
@@ -661,27 +667,11 @@ def normalize_and_hash(s: str, remove_all_whitespace: bool) -> str:
661667 "not specified, this example will create a new job."
662668 ),
663669 )
664- # Need to instantiate a GoogleAdsClient to access enums, but this is only
665- # used for help text, so it's fine if it fails.
666- try :
667- consent_status_enum_names = [
668- e .name
669- for e in GoogleAdsClient .load_from_storage (
670- version = "v20"
671- ).enums .ConsentStatusEnum
672- ]
673- except Exception :
674- consent_status_enum_names = [
675- "UNSPECIFIED" ,
676- "UNKNOWN" ,
677- "GRANTED" ,
678- "DENIED" ,
679- ]
680670 parser .add_argument (
681671 "-d" ,
682672 "--ad_user_data_consent" ,
683673 type = str ,
684- choices = consent_status_enum_names ,
674+ choices = [ e . name for e in googleads_client . enums . ConsentStatusEnum ] ,
685675 help = (
686676 "The data consent status for ad user data for all members in "
687677 "the job."
@@ -691,7 +681,7 @@ def normalize_and_hash(s: str, remove_all_whitespace: bool) -> str:
691681 "-p" ,
692682 "--ad_personalization_consent" ,
693683 type = str ,
694- choices = consent_status_enum_names ,
684+ choices = [ e . name for e in googleads_client . enums . ConsentStatusEnum ] ,
695685 help = (
696686 "The personalization consent status for ad user data for all "
697687 "members in the job."
@@ -700,12 +690,6 @@ def normalize_and_hash(s: str, remove_all_whitespace: bool) -> str:
700690
701691 args : argparse .Namespace = parser .parse_args ()
702692
703- # GoogleAdsClient will read the google-ads.yaml configuration file in the
704- # home directory if none is specified.
705- googleads_client : GoogleAdsClient = GoogleAdsClient .load_from_storage (
706- version = "v20"
707- )
708-
709693 try :
710694 main (
711695 googleads_client ,
0 commit comments