Skip to content

Commit e2f3723

Browse files
author
spirit
committed
Fix download progress under Python 2.
1 parent b62253d commit e2f3723

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

‎download_lt.py‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,21 +111,22 @@ def download_lt(update=False):
111111

112112
with closing(TemporaryFile()) as t:
113113
with closing(urlopen(url)) as u:
114-
size = int(u.headers["Content-Length"])
114+
content_len = int(u.headers["Content-Length"])
115115
sys.stdout.write(
116116
"Downloading {!r} ({:.1f} MiB)...\n"
117-
.format(filename, size / 1048576.)
117+
.format(filename, content_len / 1048576.)
118118
)
119119
sys.stdout.flush()
120-
chunk_size = size // 100
120+
chunk_len = content_len // 100
121121
data_len = 0
122122
while True:
123-
data = u.read(chunk_size)
124-
data_len += len(data)
123+
data = u.read(chunk_len)
125124
if not data:
126125
break
126+
data_len += len(data)
127127
t.write(data)
128-
sys.stdout.write("\r{:.0%}".format(data_len / size))
128+
sys.stdout.write(
129+
"\r{:.0%}".format(float(data_len) / content_len))
129130
sys.stdout.flush()
130131
sys.stdout.write("\n")
131132
t.seek(0)

0 commit comments

Comments
 (0)