Created
July 16, 2019 15:25
-
-
Save azimjohn/0f0062dc6139142acaf29703c051b220 to your computer and use it in GitHub Desktop.
Internet Speed Test logger with SpeedTest CLI
This file contains hidden or 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
# pip install speedtest-cli | |
import os | |
import csv, json | |
import subprocess | |
from datetime import datetime | |
res = subprocess.run(["speedtest-cli --server 6982 --json"], stdout=subprocess.PIPE, shell=True) | |
now = datetime.now() | |
results = json.loads(res.stdout) | |
current_dir = os.path.dirname(__file__) | |
def to_mb(speed): | |
return round(int(speed) / (1024 * 1024), 2) | |
with open(os.path.join(current_dir, 'internet_speed.csv'), 'a') as file: | |
writer = csv.writer(file) | |
if file.tell() == 0: | |
writer.writerow(["Download", "Upload", "Ping", "Server", "Datetime"]) | |
writer.writerow([ | |
to_mb(results["download"]), | |
to_mb(results["upload"]), | |
results["ping"], | |
results["server"]["sponsor"], | |
now.strftime("%d/%m/%Y %H:%M") | |
]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment