0

In Line 6 query = 'from(bucket: "my-bucket")\ how do we pass bucket as variable instead of hard-coding it ?

Code Source -> https://www.influxdata.com/blog/getting-started-with-python-and-influxdb-v2-0/ Script for writing and querying points to InfluxDB with the Python Client

from influxdb_client import InfluxDBClient

org = "my-org"
bucket = "my-bucket"
token = $my-token
query = 'from(bucket: "my-bucket")\
|> range(start: -10m)\
|> filter(fn: (r) => r._measurement == "h2o_level")\
|> filter(fn: (r) => r._field == "water_level")\
|> filter(fn: (r) => r.location == "coyote_creek")'

Note - the syntax style for query can be in these 2 ways as mentioned here - https://community.influxdata.com/t/query-throws-rparen-got-eof-error/18940

I tried multiple ways as mentioned here How do I create a multiline Python string with inline variables? , but getting error.

1 Answer 1

1

This can be solved by using concatenating strings and variables.

org = "my-org"
bucket = "my-bucket"
token = $my-token
query = 'from(bucket: "' + bucket + '")\
|> range(start: -10m)\
|> filter(fn: (r) => r._measurement == "h2o_level")\
|> filter(fn: (r) => r._field == "water_level")\
|> filter(fn: (r) => r.location == "coyote_creek")'
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.