-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
50 lines (40 loc) · 1.38 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import requests
import bs4
import os
import time
import size
import status
import urllib.request
memory = size.Memory()
url = "https://dl.astralinux.ru/astra/"
def download_filesys(url, folder_path, num_of_spaces=1):
current_folder = size.list_links(url)
for link in current_folder:
if link["size"] != '-':
status.status_print(num_of_spaces*" ", link["name"], link["size"], size=memory, current_file=link["name"]+" "+link["size"], sep=None)
memory.add(link["size"])
if not os.path.exists(folder_path+link["name"]):
try:
urllib.request.urlretrieve(url+link["name"], folder_path+link["name"])
except:
pass
for link in current_folder:
if link["size"] == '-':
try:
new_folder = os.path.join(folder_path, link["name"])
os.mkdir(new_folder)
except:
pass
status.status_print(num_of_spaces*" ",link["name"], ":", size=memory, sep=None)
download_filesys(url+link["name"], new_folder, num_of_spaces+1)
parent_dir = os.getcwd()
# create base folder
base_folder = os.path.join(parent_dir,url.split('/')[len(url.split('/'))-2]+'/')
try:
os.mkdir(base_folder)
except:
pass
download_filesys(url, base_folder)
status.status_print(size=memory, sep=None)
print()
print()