Running a look via API
Here we are going to run a look with modified filter values and retrieve the results. This demo uses this Look.
The demo is a simple look which retrieves info for a single given wallet address. This finds the look, extracts the query, updates the parameters and then runs it. Finally results are printed out.
https://github.com/ChainArgos/api-demos/blob/main/looker/look_query/look_query_demo.py
import json
import looker_sdk
## CONFIG
# This is the address to look up
BLACKLISTED_ADDRESS = '0x3b76a3699b563ad1af98ad581714c72315c83607'
# This is the look we are going to run.
# You can get this from the URL (i.e. https://dashargos.chainargos.com/looks/722 -> 722)
LOOK_ID=722
# This is the filter we want to set.
# While editing the look if you hover over the circled-i next to the relevant dimension
# this is given under "NAME"
FILTER_TITLE='address'
## BEGIN DEMO CODE
# initialize connection
sdk = looker_sdk.init40("../looker.ini")
# look up this look
look = sdk.look(look_id=str(LOOK_ID))
# grab the query
query = look.query
# build the filter we want to use here
query_filter = {
query.view + "." + FILTER_TITLE: BLACKLISTED_ADDRESS
}
# construct a new query based on the first one
new_query = sdk.create_query(
body=looker_sdk.models40.WriteQuery(model=query.model,
view=query.view,
fields=query.fields,
filters=query_filter)
)
# run it
result_raw = sdk.run_query(query_id=new_query.id, result_format='json_bi')
result = json.loads(result_raw)
# print results
assert len(result['rows']) == 1
for k, v in result['rows'][0].items():
print(str(k) + " : " + str(v))
Note this code involves manipulating the query filters. If you want to look at the filters on a given look via the API here is a code snippet to do that:
https://github.com/ChainArgos/api-demos/blob/main/looker/look_query/get_query_filters.py
import json
import looker_sdk
# This is the look we are going to run.
# You can get this from the URL (i.e. https://dashargos.chainargos.com/looks/722 -> 722)
LOOK_ID=722
# initialize connection
sdk = looker_sdk.init40("../looker.ini")
# look up this look
look = sdk.look(look_id=str(LOOK_ID))
# and print out
print(look.query.filters)
Last updated