Add influx db client to fastapi

This commit is contained in:
DingZQ
2025-01-31 13:33:47 +08:00
parent 35c3bf986c
commit 8e9859e2c1

10
main.py
View File

@@ -20,6 +20,10 @@ import random
import logging
import redis
import datetime
from influxdb_client import InfluxDBClient, BucketsApi, WriteApi, OrganizationsApi, Point, QueryApi
from typing import List, Dict
from datetime import datetime, timedelta, timezone
from dateutil import parser
JUNCTION = 0
RESERVOIR = 1
@@ -46,6 +50,12 @@ app = FastAPI()
# 用redis 限制并发访u
redis_client = redis.Redis(host="localhost", port=6379, db=0)
# influxdb数据库连接信息
influx_url = "http://localhost:8086" # 替换为你的InfluxDB实例地址
influx_token = "xGDM5RZqRJAuzAGS-otXUdC2NFdY75qJAjRLqAB4p5WcIIAlIUpOpT8_yA16AOHmJWerwQ_08gwb84sy42jnZQ==" # 替换为你的InfluxDB Token
influx_org_name = "TJWATERORG" # 替换为你的Organization名称
influx_client = InfluxDBClient(url=url, token=token, org=org_name)
# 配置日志记录器
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)