Proto1
This commit is contained in:
commit
92b9bff026
50
main.py
Normal file
50
main.py
Normal file
@ -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()
|
||||
Loading…
Reference in New Issue
Block a user