commit 92b9bff0260055ca001e8d00b974a80cfaf7bd7b Author: imp4ct Date: Thu Jul 30 17:55:19 2020 -0400 Proto1 diff --git a/main.py b/main.py new file mode 100644 index 0000000..b625dcf --- /dev/null +++ b/main.py @@ -0,0 +1,50 @@ + +# Sean Corrigan 2020 + +from influxdb import InfluxDBClient +import json +import requests + + +## Influx Settings +serverip = "192.168.0.13" +serverport = 8086 +serverdatabase = "telegraf" +servernickname = 'Yoo01pn.ddns.net' # Comes up as host in grafana/influx + + +## OpenWeatherMap Settings +lat = '43.8970929' +lon = '-78.865791' +api = '5292f0a17ecbe4b523fe0609ed2c556f' +jsonurl = "https://api.openweathermap.org/data/2.5/onecall?lat=" + lat + "&lon=" + lon + "&units=metric&appid=" + api + +def weather(): # Actual Speedtest using speedtest-cli + response = json.loads(requests.get(jsonurl).text) + return response + +def uploadInfluxdata(host='192.168.0.13', port=8086): # Main upload section + query = 'select Float_value from cpu_load_short;' + query_where = 'select Int_value from cpu_load_short where host=$host;' + bind_params = {'host': servernickname} + response = weather() + json_body = [ + { + "measurement": "OpenWeather", + "tags": { + "host": servernickname, + }, + + "fields": { + "Current Temp": response['current']['temp'], + "Humidity": response['current']['humidity'], + "Weather": response['current']['weather'][0]['main'], + + } + } + ] + + client = InfluxDBClient(host, port, database = serverdatabase) # Init connection to Influx Server + client.write_points(json_body) # Write Speedtest results + +uploadInfluxdata()