Created initial code base with some items still not working correctly such as final push to influx server.

This commit is contained in:
Sean Corrigan 2020-07-27 21:03:50 -04:00
commit 1797e6aafd

41
main.py Normal file
View File

@ -0,0 +1,41 @@
# Sean Corrigan 2020
import speedtest
import json
from influxdb import InfluxDBClient
def speed(): # To be called on schedule
servers = [] # If you want to test against a specific server
threads = 4
# Choose the amount of threads to use for the test
test = speedtest.Speedtest()
test.get_servers(servers)
test.get_best_server()
test.download(threads=threads)
test.upload(threads=threads)
test.results.share()
results = test.results.dict()
resultlist = []
resultupload = {}
resultupload["UploadSpeed"] = results["upload"]
resultdownload = {}
resultdownload["DownloadSpeed"] = results["download"]
resultlatency = {}
resultlatency["Latency"] = results["ping"]
resultlist.append(resultupload)
resultlist.append(resultdownload)
resultlist.append(resultlatency)
resultforupload = json.dumps(resultlist)
print(resultforupload)
return(resultforupload)
def influxupload(): # Still having errors in uploading the data..
jsondata = speed()
client = InfluxDBClient(host='192.168.0.13', port=8086, database='telegraf')
client.write(str(jsondata), protocol='json')
influxupload()