From 7b8858b3ec00944aad6c0151162079a7854bf812 Mon Sep 17 00:00:00 2001 From: psykok Date: Mon, 5 Aug 2024 10:55:02 +0200 Subject: [PATCH 1/3] added option to use custom influxdb using a json file --- netatmo_influx.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/netatmo_influx.py b/netatmo_influx.py index 08e5df1..c4481ea 100755 --- a/netatmo_influx.py +++ b/netatmo_influx.py @@ -3,15 +3,29 @@ import lnetatmo from influxdb import InfluxDBClient +from os.path import expanduser, exists +import json + +INFLUXCONFIG = "~/.netatmo.mysql" +if (INFLUXCONFIG): + influxconfigFile = expanduser(INFLUXCONFIG) + with open(influxconfigFile, "r") as f: + influxconfig = {k.upper():v for k,v in json.loads(f.read()).items()} + + #print(influxconfig) + client = InfluxDBClient(host=influxconfig["INFLUX_HOST"], port=influxconfig["INFLUX_PORT"]) +else: + #print("default") + client = InfluxDBClient() authorization = lnetatmo.ClientAuth() weatherData = lnetatmo.WeatherStationData(authorization) -client = InfluxDBClient() if {'name': 'netatmo'} not in client.get_list_database(): client.create_database('netatmo') +print(weatherData.stationByName()) for station in weatherData.stations: station_data = [] module_data = [] From 779eebfd8b032c961a00999bf80afed52db0e012 Mon Sep 17 00:00:00 2001 From: psykok Date: Mon, 5 Aug 2024 11:20:29 +0200 Subject: [PATCH 2/3] changed position of the influxdb creation --- netatmo_influx.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/netatmo_influx.py b/netatmo_influx.py index c4481ea..0997b72 100755 --- a/netatmo_influx.py +++ b/netatmo_influx.py @@ -6,7 +6,15 @@ from os.path import expanduser, exists import json +# +# custom influx config file +# +# { +# "INFLUX_HOST" : "", +# "INFLUX_PORT" : "", +# } INFLUXCONFIG = "~/.netatmo.mysql" + if (INFLUXCONFIG): influxconfigFile = expanduser(INFLUXCONFIG) with open(influxconfigFile, "r") as f: @@ -17,15 +25,14 @@ else: #print("default") client = InfluxDBClient() + if {'name': 'netatmo'} not in client.get_list_database(): + client.create_database('netatmo') authorization = lnetatmo.ClientAuth() weatherData = lnetatmo.WeatherStationData(authorization) -if {'name': 'netatmo'} not in client.get_list_database(): - client.create_database('netatmo') - -print(weatherData.stationByName()) +#print(weatherData.stationByName()) for station in weatherData.stations: station_data = [] module_data = [] From e64f94ef2f045e42915ab279cb96cf1fa53d43b5 Mon Sep 17 00:00:00 2001 From: psykok Date: Mon, 5 Aug 2024 11:25:24 +0200 Subject: [PATCH 3/3] changed the name of the default influxdb config file --- netatmo_influx.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netatmo_influx.py b/netatmo_influx.py index 0997b72..fbcc6cb 100755 --- a/netatmo_influx.py +++ b/netatmo_influx.py @@ -13,7 +13,7 @@ # "INFLUX_HOST" : "", # "INFLUX_PORT" : "", # } -INFLUXCONFIG = "~/.netatmo.mysql" +INFLUXCONFIG = "~/.netatmo.influxdb" if (INFLUXCONFIG): influxconfigFile = expanduser(INFLUXCONFIG)