Debian Codegraph @

examples/file_progress.py

raw
1 from time import sleep
2 from urllib.request import urlopen
3
4 from rich.progress import wrap_file
5
6 # Read a URL with urlopen
7 response = urlopen("https://www.textualize.io")
8 # Get the size from the headers
9 size = int(response.headers["Content-Length"])
10
11 # Wrap the response so that it update progress
12
13 with wrap_file(response, size) as file:
14 for line in file:
15 print(line.decode("utf-8"), end="")
16 sleep(0.1)