import os
import sys




"""
def download(url, path):
    elements = []
    searcher = searching(url)
    html_files, img_files, css_files, script_files = searcher.all_files()
    elements.extend(html_files)
    elements.extend(img_files)
    elements.extend(css_files)
    elements.extend(script_files)
    manager = filemanager(elements)
    manager.build_directorys(path)
    os.chdir(path)
    print(elements)
    for file in elements:
        url = url + file
        re = requests.get(url).content
        with open(file, 'wb') as f: # create file
            f.write(re)
"""

class localmanager(object):
    def __init__(self, elements):
        self.elements = elements

    def build_path(self, path):
        directory = []
        for element in self.elements:
            if not element.startswith('http'):
                slicing = element.split('/')
                file_name = slicing.pop()
                directory.append('/'.join(slicing))

        # remove duplicates from the lists of elements && sorted by length
        directory = list(dict.fromkeys(directory))
        directory.sort(key=len)

        os.chdir(path)
        for _dir in directory:
            if _dir != '':
                os.makedirs(_dir)



# directory = ['/'.join(element.split('/').pop()) for element in self.elements if not element.startswith('http')]
import os
import sys




"""
def download(url, path):
    elements = []
    searcher = searching(url)
    html_files, img_files, css_files, script_files = searcher.all_files()
    elements.extend(html_files)
    elements.extend(img_files)
    elements.extend(css_files)
    elements.extend(script_files)
    manager = filemanager(elements)
    manager.build_directorys(path)
    os.chdir(path)
    print(elements)
    for file in elements:
        url = url + file
        re = requests.get(url).content
        with open(file, 'wb') as f: # create file
            f.write(re)
"""

class localmanager(object):
    def __init__(self, elements):
        self.elements = elements

    def build_path(self, path):
        directory = []
        for element in self.elements:
            if not element.startswith('http'):
                slicing = element.split('/')
                file_name = slicing.pop()
                directory.append('/'.join(slicing))

        # remove duplicates from the lists of elements && sorted by length
        directory = list(dict.fromkeys(directory))
        directory.sort(key=len)

        os.chdir(path)
        for _dir in directory:
            if _dir != '':
                os.makedirs(_dir)



# directory = ['/'.join(element.split('/').pop()) for element in self.elements if not element.startswith('http')]
def download(url, path):     elements = []     searcher = searching(url)     html_files, img_files, css_files, script_files = searcher.all_files()     elements.extend(html_files)     elements.extend(img_files)     elements.extend(css_files)     elements.extend(script_files)     manager = filemanager(elements)     manager.build_directorys(path)     os.chdir(path)     print(elements)     for file in elements:         url = url + file         re = requests.get(url).content         with open(file, 'wb') as f: # create file             f.write(re) # remove duplicates from the lists of elements && sorted by length # directory = ['/'.join(element.split('/').pop()) for element in self.elements if not element.startswith('http')]