def cli(state, account_id, query): state.finalize(query) client = setup_client() query_method = google_ads_query(client, str(account_id)) if len(query) == 0: run_as_repl(query_method, state, completion=True) else: rows = query_method(parse_query(' '.join(query))) write_rows(rows, state)
def fields(state, query): """Make queries about field metadata for GoogleAds entities""" state.finalize(query) client = setup_client() query_method = google_fields_query(client) if len(query) == 0: run_as_repl(query_method, state, completion=False) else: rows = query_method(parse_query(' '.join(query))) write_rows(rows, state)
def fields_for(state, entity): """Query selectable fields for a specific entity""" state.finalize(entity) client = setup_client() query_method = google_fields_query(client) query = f"SELECT name, attribute_resources, selectable_with WHERE name = '{entity}'" print_gaql(query) rows = query_method(parse_query(query)) write_rows(rows, state)
def clients_cmd(state): client = setup_client() query_method = google_ads_query(client, get_root_client()) query = f"""SELECT customer.id, customer_client.descriptive_name, customer_client.id FROM customer_client LIMIT 1000""" print_gaql(query) rows = query_method(query) write_rows(rows, state)
def run_as_repl(run_query, state, completion): setup_session(completion) print('running in interactive mode, write some GAQL...') try: while True: query = read_query() if query: print_gaql(query, _SESSION.lexer.pygments_lexer) try: rows = run_query(query) write_rows(rows, state) except google.ads.google_ads.errors.GoogleAdsException as ex: handle_google_ads_error(ex) except (EOFError, KeyboardInterrupt): print('\nBye!')