Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
speedtest cron
#!/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)
#!/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
You can’t perform that action at this time.