Tools > General
General shared utilities.
This module provides utility functions for common tasks such as downloading files from the internet and extract zip files.
clear_folder(folder_path)
Remove all files and subdirectories within a specified folder.
This function deletes all contents within the specified folder, including files and subdirectories, while keeping the folder itself intact.
Parameters
folder_path : str The path to the folder to be cleared.
Raises
FileNotFoundError If the specified folder does not exist.
Source code in app/tools/general.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
|
download_file(url, file_name, save_path, chunk_size=128)
Download a file from a given URL and save it to a specified path.
Parameters
url : str The URL of the file to be downloaded. file_name : str The name of the file to be saved locally. save_path : str The local folder where the downloaded file will be saved. chunk_size : int, optional The size of chunks for downloading the file, defaults to 128 bytes.
Returns
None The function writes the downloaded file to the specified location.
Raises
Exception If an error occurs during the download or file writing process.
Source code in app/tools/general.py
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 47 48 49 50 51 52 53 54 55 56 |
|
extract_zip(zip_path, zip_file, extract_to)
Extract the contents of a zip file to the specified directory.
Parameters
zip_path : str The path to the zip file. zip_file : str The name of the zip file. extract_to : str The directory where the contents of the zip file will be extracted.
Source code in app/tools/general.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
|