Created
January 7, 2022 20:38
-
-
Save vwillcox/98a60ead9e17c9782946583e45ef3e08 to your computer and use it in GitHub Desktop.
Speedtest.net Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import json | |
import sys | |
import time | |
proc = subprocess.Popen(['/home/pi/speedtest -p -f json'], shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE) | |
for i in proc.stdout: | |
output = proc.stdout.readline() | |
results = json.loads(output) | |
for key in results: | |
if results["type"]=='download': | |
download = results["download"]["bandwidth"] | |
down = str(round(download / 125000, 2)) | |
print("Download: "+ down + "Mbps") | |
elif results["type"]=='upload': | |
upload = results["upload"]["bandwidth"] | |
up = str(round(upload / 125000, 2)) | |
print("upload: "+ up + "Mbps") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment