-
-
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
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
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