Sunday, May 29, 2022

Python - SpeedTest with Power BI

 


Python Code:

#!/usr/bin/env python
# coding: utf-8
# In[1]:
import time
import pandas as pd
import numpy as np
import schedule
import speedtest
from threading import Timer
import sys

Path = "C:\\Users\\...\\Python\\SpeedTest\\"

File = 'dados_SpeedTest.xlsx'
PathFile = Path + File
print(PathFile)

# In[2]:
##################################################################################################
#BEGIN Time
from datetime import datetime
from dateutil.relativedelta import relativedelta
def diff(t_aFull, t_bFull):
    t_diffFull = relativedelta(t_bFull, t_aFull)  # later/end time comes first!
    return '{h}h {m}m {s}s'.format(h=t_diffFull.hours, m=t_diffFull.minutes, s=t_diffFull.seconds)
t_aFull = datetime.now()
t_aFull

##################################################################################################

# In[3]:
def Internet():
    df = pd.read_excel(PathFile, sheet_name='data')
    s = speedtest.Speedtest()
    data_atual = datetime.now().strftime('%d/%m/%Y')
    hora_atual = datetime.now().strftime('%H:%M')
    speed = s.download(threads=None)*(10**-6)
    df.loc[len(df)]=[data_atual,hora_atual,speed]
    df.to_excel(PathFile,sheet_name='data',index=False)
    Timer(1800,Internet).start()

# In[4]:

Internet()


# In[5]:
##################################################################################################
#Script de Tempo End
t_bFull = datetime.now()
diff(t_aFull,t_bFull)
print("========================== ")
print("Time:: ",diff(t_aFull,t_bFull))
print("==========================")

#quit()
exit()
sys.exit()







No comments:

Post a Comment

Power BI APP - Delete or Unpublish

 UNPUBLISH DELETE