Skip to content

Instantly share code, notes, and snippets.

@zokis
Created March 8, 2017 16:54
Show Gist options
  • Save zokis/710c3c015e0832b1dc44e807baee54c6 to your computer and use it in GitHub Desktop.
Save zokis/710c3c015e0832b1dc44e807baee54c6 to your computer and use it in GitHub Desktop.
Runs an internet speed test every 1 hour; Throws the result into a csv file named speedtest_result.csv
# coding: utf-8
# pip install speedtest-cli
import subprocess
import time
def main():
c = 0
with open('speedtest_result.csv', 'w') as file:
process = subprocess.Popen(['speedtest', '--csv-header'], stdout=subprocess.PIPE)
out, err = process.communicate()
file.writelines([out])
print 'Writing header'
try:
while True:
c += 1
print 'Writing speed test %s' % c
process = subprocess.Popen(['speedtest', '--csv'], stdout=subprocess.PIPE)
out, err = process.communicate()
file.writelines([out])
print 'Sleeping 1hr'
time.sleep(3600)
except KeyboardInterrupt:
exit(0)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment