def autocomplete_fields():
    """Dumps entity fields from Google, building a single large JSON which provides the seed data for autocompletion"""
    state = State()
    state.format = 'json'

    client = setup_client()
    query_method = google_fields_query(client)

    resources_path = pathlib.Path('gaql/lib/google_clients/completion/entities.json')
    resource_rows = query_method(resources_query())
    resources = { resource.name: to_dict(resource) for resource in resource_rows }
    if resources_path.exists():
        with resources_path.open('r') as f:
            existing_resources = json.load(f)
            for k in existing_resources:
                resources[k] = existing_resources[k]

    for resource_name, resource_dict in resources.items():
        if "fields" in resource_dict:
            continue
        print(f"Dumping {resource_name} to json")

        resource_dict["fields"] = []
        attributes = query_method(attributes_query(resource_name))
        for attribute in attributes:
            resource_dict["fields"].append(attribute.name)

    with resources_path.open('w') as f:
        json.dump(resources, fp=f)
Пример #2
0
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)
Пример #3
0
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)
Пример #4
0
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)
Пример #5
0
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)