Skip to content

Instantly share code, notes, and snippets.

@jab416171
Last active August 29, 2015 14:24
Show Gist options
  • Save jab416171/510eb425bbb3d8fb3acd to your computer and use it in GitHub Desktop.
Save jab416171/510eb425bbb3d8fb3acd to your computer and use it in GitHub Desktop.
#!/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 = ['https://spreadsheets.google.com/feeds']
credentials = SignedJwtAssertionCredentials(json_key['client_email'], json_key['private_key'], scope)
gc = gspread.authorize(credentials)
document = gc.open("Speedtest Results")
worksheet = document.worksheet("main")
data = (timestamp, ping, up, down)
column_count = len(data)
if worksheet.col_count < column_count:
worksheet.resize(cols=column_count)
worksheet.append_row(data)
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
#http://gspread.readthedocs.org/en/latest/oauth2.html
#!/bin/sh
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