File: file_progress.py

package info (click to toggle)
rich 13.9.4-1.1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 20,284 kB
  • sloc: python: 29,157; makefile: 29
file content (16 lines) | stat: -rw-r--r-- 423 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
from time import sleep
from urllib.request import urlopen

from rich.progress import wrap_file

# Read a URL with urlopen
response = urlopen("https://www.textualize.io")
# Get the size from the headers
size = int(response.headers["Content-Length"])

# Wrap the response so that it update progress

with wrap_file(response, size) as file:
    for line in file:
        print(line.decode("utf-8"), end="")
        sleep(0.1)