Amazing-Python-Scripts

Форк
0
40 строк · 930.0 Байт
1
"""
2
    File Downloader
3

4
        This python script will help users to download any kind of files, irrespective of their size from the internet.<br>
5
        You just need to have the url and you are good to go!
6
"""
7
import os
8
import requests
9
from tqdm import tqdm
10
import math
11
import time
12

13
url = input("Enter the url of the file you want to download: ")
14

15
r = requests.get(url)
16
# receives data from the url
17

18
file_size = int(r.headers['Content-Length'])
19
chunk_size = 256
20

21
"""Chunk size is the
22
number of bytes downloaded at a time
23
"""
24

25
r = requests.get(url, stream=True)
26

27
"""streams=True ensures that
28
will not get data at once, but will get data one by one
29

30
"""
31

32
extension = (os.path.splitext(url))[-1]
33
file = "file"+extension
34

35
iterations = math.ceil(file_size/chunk_size)
36

37
with open(file, "wb") as file:
38
    for chunk in tqdm(r.iter_content(chunk_size=chunk_size), total=iterations):
39
        time.sleep(0.5)
40
        file.write(chunk)
41

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.