Skip to content

Instantly share code, notes, and snippets.

Last active Aug 29, 2015
What would you like to do?
#!/usr/bin/env python
import gspread
import sys
import json
from oauth2client.client import SignedJwtAssertionCredentials
timestamp = sys.argv[1]
ping = sys.argv[2]
up = sys.argv[3]
down = sys.argv[4]
json_key = json.load(open('/path/to/my-123123123.json'))
scope = ['']
credentials = SignedJwtAssertionCredentials(json_key['client_email'], json_key['private_key'], scope)
gc = gspread.authorize(credentials)
document ="Speedtest Results")
worksheet = document.worksheet("main")
data = (timestamp, ping, up, down)
column_count = len(data)
if worksheet.col_count < column_count:
yum install gcc python-devel openssl-devel libffi-devel
pip install gspread
pip install oauth2client
pip install PyOpenSSL
#See here for instructions on the oauth json setup
result=$(/bin/speedtest-cli --simple)
download=$(echo $result | grep -oP "(?<=Download: )[0-9\.]* .*?/s")
upload=$(echo $result | grep -oP "(?<=Upload: )[0-9\.]* .*?/s")
ping=$(echo $result | grep -oP "(?<=Ping: )[0-9\.]* .*?ms")
addToSpreadsheet "$(date)" "$upload" "$download" "$ping"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment