add download meter
This commit is contained in:
parent
08f0dd27f7
commit
ed0696721f
1 changed files with 13 additions and 0 deletions
|
@ -36,9 +36,22 @@ async def main():
|
|||
async with ctx.session.get(url) as resp:
|
||||
assert resp.status == 200
|
||||
|
||||
total_length = int(resp.headers["content-length"])
|
||||
downloaded_bytes = 0
|
||||
download_ratio = 0
|
||||
|
||||
log.info("to download %d bytes", total_length)
|
||||
|
||||
with tempfile.TemporaryFile() as temp_fd:
|
||||
async for chunk in resp.content.iter_chunked(8192):
|
||||
temp_fd.write(chunk)
|
||||
downloaded_bytes += len(chunk)
|
||||
new_download_ratio = round(
|
||||
(downloaded_bytes / total_length) * 100
|
||||
)
|
||||
if new_download_ratio != download_ratio:
|
||||
log.info("download at %d%%", download_ratio)
|
||||
download_ratio = new_download_ratio
|
||||
|
||||
# write to output
|
||||
log.info("copying temp to output")
|
||||
|
|
Loading…
Reference in a new issue