Skip to content

Instantly share code, notes, and snippets.

@vwillcox
Created January 7, 2022 20:38
Show Gist options
  • Save vwillcox/98a60ead9e17c9782946583e45ef3e08 to your computer and use it in GitHub Desktop.
Save vwillcox/98a60ead9e17c9782946583e45ef3e08 to your computer and use it in GitHub Desktop.
Speedtest.net Python
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