Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

envia por email a velocidade da internet #84

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions NetworkSpeed/speed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/python3
# por Lucas Carrafa
import smtplib
import os
import commands
from email.mime.text import MIMEText
import time

def envia_email(texto):
informacao = "A velocidade da rede esta em " + str(texto) +" Mbit/s" #corpo do email

msg = MIMEText(informacao)
msg['Subject'] = "Velocidade da rede!"
msg['From'] = "email remetente"
msg['To'] = "email destino"

server = smtplib.SMTP('smtp.gmail.com', 587) #servidor de email SMTP, nesse exemplo Gmail
server.starttls()
server.login("inserir um email", "senha")

server.sendmail("email remetente","email destino", msg.as_string())
server.quit()


def verifica_rede(): #executa no shell um comando e retorna o resultado
return commands.getstatusoutput("speedtest-cli")

def retira_dados(dado): #funcao que pega apenas a velocidade
ini = "Download: "
fim = " Mbit/s"
tam = len(ini)
p_ini = dado.find(ini) + tam
p_fim = dado.find(fim)
return dado[p_ini:p_fim]

#_____________MAIN_______________#

while True:
aux = verifica_rede()
envia_email(retira_dados(aux[1]))
time.sleep(43200) #aguarda 12 horas para enviar o proximo