Created
July 5, 2016 19:42
-
-
Save jab416171/6824a0d963fcef6a307083e3f5ce8efd to your computer and use it in GitHub Desktop.
speedtest cron
This file contains 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
#!/usr/bin/env python | |
import gspread | |
import sys | |
import json | |
from oauth2client.service_account import ServiceAccountCredentials | |
timestamp = sys.argv[1] | |
ping = sys.argv[2] | |
up = sys.argv[3] | |
down = sys.argv[4] | |
sheet = sys.argv[5] | |
scope = ['https://spreadsheets.google.com/feeds'] | |
credentials = ServiceAccountCredentials.from_json_keyfile_name('some-filename.json', scope) | |
gc = gspread.authorize(credentials) | |
document = gc.open("Speedtest Results") | |
worksheet = document.worksheet(sheet) | |
data = (timestamp, ping, up, down) | |
column_count = len(data) | |
if worksheet.col_count < column_count: | |
worksheet.resize(cols=column_count) | |
worksheet.append_row(data) |
This file contains 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
#!/bin/sh | |
result=$(/bin/speedtest-cli --simple) | |
download=$(echo $result | grep -oP "(?<=Download: )[0-9\.]* .*?/s" | cut -d " " -f 1) | |
upload=$(echo $result | grep -oP "(?<=Upload: )[0-9\.]* .*?/s" | cut -d " " -f 1) | |
ping=$(echo $result | grep -oP "(?<=Ping: )[0-9\.]* .*?ms" | cut -d " " -f 1) | |
addToSpreadsheet "$(date)" "$upload" "$download" "$ping" main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment