33 lines
799 B
Python
33 lines
799 B
Python
from influxdb_client import InfluxDBClient, Point, WriteOptions
|
|
from influxdb_client.client.query_api import QueryApi
|
|
import influxdb_info
|
|
|
|
# 配置 InfluxDB 连接
|
|
url = influxdb_info.url
|
|
token = influxdb_info.token
|
|
org = influxdb_info.org
|
|
bucket = "SCADA_data"
|
|
|
|
# 创建 InfluxDB 客户端
|
|
client = InfluxDBClient(url=url, token=token, org=org)
|
|
|
|
# 创建查询 API 对象
|
|
query_api = client.query_api()
|
|
|
|
# 构建查询语句
|
|
query = f'''
|
|
from(bucket: "{bucket}")
|
|
|> range(start: -1h)
|
|
'''
|
|
|
|
# 执行查询
|
|
result = query_api.query(query)
|
|
|
|
# 处理查询结果
|
|
for table in result:
|
|
for record in table.records:
|
|
print(f"Time: {record.get_time()}, Value: {record.get_value()}, Measurement: {record.get_measurement()}, Field: {record.get_field()}")
|
|
|
|
# 关闭客户端连接
|
|
client.close()
|