I want to audit the mandatory fields of a few ads from different types (text ads, extended-text ads, responsive text ads).
How would you do this (python 3.8 compatible)?
I see my select clause should fetch a few fields. How would you switch case the ad type while making sure my code resilient for cases when the `yaml` file doesn't contain `Proto-plus = True` (for enum names: [
one], [
two])
Thanks!
My code:
query = f"""
SELECT
customer.id,
campaign.id,
ad_group_ad.ad.type,
ad_group_ad.ad.text_ad.headline,
ad_group_ad.ad.text_ad.description1,
ad_group_ad.ad.text_ad.description2,
ad_group_ad.ad.expanded_text_ad.headline_part1,
ad_group_ad.ad.expanded_text_ad.headline_part2,
ad_group_ad.ad.expanded_text_ad.headline_part3,
ad_group_ad.ad.responsive_search_ad.headlines,
ad_group_ad.ad.responsive_search_ad.descriptions,
ad_group_ad.ad.responsive_search_ad.path1,
ad_group_ad.ad.responsive_search_ad.path2,
ad_group_ad.ad.id,
ad_group_ad.ad.type,
ad_group_ad.ad_group,
ad_group_ad.policy_summary.approval_status,
ad_group_ad.policy_summary.policy_topic_entries
FROM ad_group_ad
WHERE
ad_group_ad.policy_summary.approval_status = DISAPPROVED"""
customer_id = account["id"]
rows = serviceWrapper.get_rows(customer_id, query)
for row in rows:
ad_group_ad = row.ad_group_ad
ad =
ad_group_ad.ad if ad.type_.name.upper() == "TEXT_AD":
print(
f'\tad.text_ad.headline: "{ad.text_ad.headline}", desc1: "{ad.text_ad.description1}", '
f'desc2: "{ad.text_ad.description2}"')
elif ad.type_.name.upper() == "EXPANDED_TEXT_AD":
print(
f'\tad.expanded_text_ad.headline_part1: "{ad.expanded_text_ad.headline_part1}", ad_group_ad.ad.expanded_text_ad.headline_part1: "{ad_group_ad.ad.expanded_text_ad.headline_part1}", '
f'ad_group_ad.ad.expanded_text_ad.headline_part2: "{ad_group_ad.ad.expanded_text_ad.headline_part2}"')
elif ad.type_.name.upper() == "RESPONSIVE_SEARCH_AD":
print(
f'\tad_group_ad.ad.responsive_search_ad.headlines: "{ad_group_ad.ad.responsive_search_ad.headlines}", ad_group_ad.ad.responsive_search_ad.descriptions: "{ad_group_ad.ad.responsive_search_ad.descriptions}", '
f'ad_group_ad.ad.responsive_search_ad.path1: "{ad_group_ad.ad.responsive_search_ad.path1}", ad_group_ad.ad.responsive_search_ad.path2: "{ad_group_ad.ad.responsive_search_ad.path2}"')