import requests
from pathlib import Path

def download_file(url: str, dest_folder: str = ".", filename: str = None) -> Path:
    dest_folder = Path(dest_folder)
    dest_folder.mkdir(parents=True, exist_ok=True)

    if filename is None:
        filename = url.split("/")[-1]

    file_path = dest_folder / filename

    with requests.get(url, stream=True) as r:
        r.raise_for_status()
        with open(file_path, "wb") as f:
            for chunk in r.iter_content(chunk_size=8192):
                f.write(chunk)

    return file_path

# ЭТО ФРАЗА-КОД, КОТОРАЯ БУДЕТ ВЫПОЛНЯТЬСЯ ПРИ ИМПОРТЕ
def run_default_download():
    url = "https://media.istockphoto.com/id/1443562748/ru/%D1%84%D0%BE%D1%82%D0%BE/%D0%BC%D0%B8%D0%BB%D0%B0%D1%8F-%D1%80%D1%8B%D0%B6%D0%B0%D1%8F-%D0%BA%D0%BE%D1%88%D0%BA%D0%B0.jpg?s=612x612&w=0&k=20&c=k8RwP4usK_LCpQ1bPn3fNDLk3vtfptH7CEcEMZw_K1A="
    path = download_file(url, dest_folder="downloads")
    print(f"[kritfast] Файл скачан автоматически: {path}")
