Skip to content

Instantly share code, notes, and snippets.

@jgamblin
Created June 23, 2017 19:11
Show Gist options
  • Save jgamblin/3428a164e561baee829c339ac1982e5c to your computer and use it in GitHub Desktop.
Save jgamblin/3428a164e561baee829c339ac1982e5c to your computer and use it in GitHub Desktop.
Simple Script To Run A Speedtest And Write Results To CSV.
#!/usr/bin/python
import os
import sys
import csv
import datetime
import time
#run speedtest-cli
print 'running test'
speed = os.popen("speedtest-cli --simple").read()
print 'done'
#split the 3 line result (ping,down and up)
lines = speed.split('\n')
print speed
ts = time.time()
now = time.strftime('%d-%m-%Y %H:%M:%S')
#if speedtest could not connect set the speeds to 0
if "Cannot" in speed:
p = 0
d = 0
u = 0
#extract the values for ping, down and up values
else:
p = lines[0][6:11]
d = lines[1][10:16]
u = lines[2][8:12]
print now,p, d, u
#save the data to a csv
out_file = open('speed.csv', 'a')
writer = csv.writer(out_file)
writer.writerow((now,p,d,u))
out_file.close()
@elcio96
Copy link

elcio96 commented Apr 24, 2020

How to edit time to run the script in line 15?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment