diff --git a/build_database.py b/build_database.py index 6f521dc..4d577e8 100644 --- a/build_database.py +++ b/build_database.py @@ -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")