Skip to content

Instantly share code, notes, and snippets.

@hemanth22
Forked from sgobin/speedtest.py
Created January 19, 2019 17:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hemanth22/93c929ed2cf35e9602854e63cf0cb70d to your computer and use it in GitHub Desktop.
Save hemanth22/93c929ed2cf35e9602854e63cf0cb70d to your computer and use it in GitHub Desktop.
Usando uma raspberry e speedtest.net para medir a velocidade da internet e salvar em uma planilha do Google via IFTTT
import os
import re
import subprocess
import time
import requests
#Usa um Webhook do IFTTT
URL = 'https://maker.ifttt.com/trigger/{NOME DO TRIGGER}/with/key/{CHAVE}'
#speedtest-cli => pip install speedtest-cli
response = subprocess.Popen('speedtest-cli --simple', shell=True, stdout=subprocess.PIPE).stdout.read()
ping = re.findall('Ping:\s(.*?)\s', response, re.MULTILINE)
download = re.findall('Download:\s(.*?)\s', response, re.MULTILINE)
upload = re.findall('Upload:\s(.*?)\s', response, re.MULTILINE)
ping[0] = ping[0].replace(',', '.')
download[0] = download[0].replace(',', '.')
upload[0] = upload[0].replace(',', '.')
# Salva em um csv local também
try:
if os.stat('/home/pi/speedtest/speedtest.csv').st_size == 0:
print 'Date,Time,Ping (ms),Download (Mbit/s),Upload (Mbit/s)'
except:
pass
report = {}
report['value1'] = ping[0]
report['value2'] = download[0]
report['value3'] = upload[0]
requests.post(URL, data=report)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment