import time # to use it later with downloading Rate,
import urllib.request # to download a file
url = "http://xxxx.xxx.com/xxx/Setup.exe"
file_name = url[-9:] # file name will be setup.exe just for Ex .
class Download(): # i'm useing a Class but its ok if you have an answer in another way .
def __init__(self):
urllib.request.urlretrieve(url, file_name, self.progress)
def progress(self,block,blocksize,total):
print("Total : \t\t",total)
downloaded = block * blocksize
print("Downlaoded : \t\t",downloaded)
left = total - downloaded
print("Left : \t\t",left)
percent = downloaded * 100 / total
print("Percent : \t\t",percent)
print("Rate : \t\t",self.rate_return(downloaded)) # i dont get it .
def rate_return(self,current_size):
while True:
# here is my problem ! i know its size / time to get Rate of downloading file .
# but its totaly wrong :(
return (current_size/1024)/time.time()
# size / 1024 to convert it to KB . / time in seconds .
Download()
.................
вывод:
Итого: 10913768 # Хорошо
Загрузок: 385024 # Хорошо
Слева: 10528744 # Хорошо
Процент: 3,527874149423004 # Хорошо
Оценка: 2,3952649685390823e-07 # Неверно?я знаю, что это около 1,5
вопрос в том, как получить скорость загрузки, пока файл еще загружается.