Commit a11333c5 authored by Nikita Yurishev's avatar Nikita Yurishev

changed influxConnection added env

parent c7748a1d
from influxdb import InfluxDBClient from influxdb import InfluxDBClient
import os
from dotenv import load_dotenv
load_dotenv('creds.env')
import time import time
class InfluxConnection: class InfluxConnection:
def __init__(self): def __init__(self):
# Конфиги # Получение конфигурации из переменных окружения
self.INFLUXDB_URL = 'http://influxdb.k8s.eterfund.ru' self.INFLUXDB_URL = os.getenv('INFLUXDB_URL')
self.INFLUXDB_DB = '' self.INFLUXDB_DB = os.getenv('INFLUXDB_DB')
self.INFLUXDB_USER = '' self.INFLUXDB_USER = os.getenv('INFLUXDB_USER')
self.INFLUXDB_PASSWORD = '' self.INFLUXDB_PASSWORD = os.getenv('INFLUXDB_PASSWORD')
# Разделение URL на хост и порт # Разделение URL на хост и порт
url_parts = self.INFLUXDB_URL.split('://')[1].split(':') url_parts = self.INFLUXDB_URL.split('://')[1].split(':')
...@@ -23,7 +27,6 @@ class InfluxConnection: ...@@ -23,7 +27,6 @@ class InfluxConnection:
database=self.INFLUXDB_DB database=self.INFLUXDB_DB
) )
def write_data(self, sensor_id, values): def write_data(self, sensor_id, values):
json_body = [ json_body = [
{ {
...@@ -43,4 +46,3 @@ class InfluxConnection: ...@@ -43,4 +46,3 @@ class InfluxConnection:
def __del__(self): def __del__(self):
self.client.close() self.client.close()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment