import urllib.request
import zipfile
import os

FILES = {
    "ai_search": "https://github.com/pacyandrocash-prog/absd-asstes/blob/main/prac2.rar",
    "ml_examples": "https://github.com/pacyandrocash-prog/absd-asstes/blob/main/prac3.rar",
    "nlp_tools": "https://github.com/pacyandrocash-prog/absd-asstes/blob/main/prac7.rar",
    "expert_systems": "https://github.com/pacyandrocash-prog/absd-asstes/blob/main/prac8.rar",
}

def down(extract=True):

    base_folder = os.path.abspath("absd_downloads")
    os.makedirs(base_folder, exist_ok=True)

    for name, url in FILES.items():

        zip_path = os.path.join(base_folder, f"{name}.zip")
        extract_path = os.path.join(base_folder, name)

        if not os.path.exists(zip_path) and not os.path.exists(extract_path):

            urllib.request.urlretrieve(url, zip_path)

            if extract:
                with zipfile.ZipFile(zip_path, "r") as z:
                    z.extractall(extract_path)

    print(base_folder)