diff --git a/netatmo_influx.py b/netatmo_influx.py index 08e5df1..fbcc6cb 100755 --- a/netatmo_influx.py +++ b/netatmo_influx.py @@ -3,15 +3,36 @@ import lnetatmo from influxdb import InfluxDBClient +from os.path import expanduser, exists +import json -authorization = lnetatmo.ClientAuth() +# +# custom influx config file +# +# { +# "INFLUX_HOST" : "", +# "INFLUX_PORT" : "", +# } +INFLUXCONFIG = "~/.netatmo.influxdb" -weatherData = lnetatmo.WeatherStationData(authorization) +if (INFLUXCONFIG): + influxconfigFile = expanduser(INFLUXCONFIG) + with open(influxconfigFile, "r") as f: + influxconfig = {k.upper():v for k,v in json.loads(f.read()).items()} -client = InfluxDBClient() -if {'name': 'netatmo'} not in client.get_list_database(): + #print(influxconfig) + client = InfluxDBClient(host=influxconfig["INFLUX_HOST"], port=influxconfig["INFLUX_PORT"]) +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) + +#print(weatherData.stationByName()) for station in weatherData.stations: station_data = [] module_data = []