完成基本功能。
This commit is contained in:
parent
b0c625bf5c
commit
d6ebd624ef
|
|
@ -0,0 +1 @@
|
||||||
|
venv
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
import requests
|
||||||
|
import datetime
|
||||||
|
|
||||||
|
# file_size if byte
|
||||||
|
|
||||||
|
|
||||||
|
def download_file(url, chunk_size=64 * 1024, file_size=100 * 1024 * 1024):
|
||||||
|
chunk_read = 0
|
||||||
|
s_time = datetime.datetime.now()
|
||||||
|
e_time = None
|
||||||
|
with requests.get(url, stream=True) as r:
|
||||||
|
for chunk in r.iter_content(chunk_size):
|
||||||
|
if chunk_read >= file_size:
|
||||||
|
e_time = datetime.datetime.now()
|
||||||
|
break
|
||||||
|
if chunk:
|
||||||
|
chunk_read += len(chunk)
|
||||||
|
duration = (e_time - s_time).total_seconds()
|
||||||
|
speed = chunk_read / duration / 1024 / 1024 * 8 # mega bit
|
||||||
|
# print("{} MB download".format(chunk_read / 1024 / 1024))
|
||||||
|
# print("{} seconds".format(duration / 1))
|
||||||
|
return speed
|
||||||
Loading…
Reference in New Issue