sinatools.DataDownload.downloader

sinatools.DataDownload.downloader.download_file(url, dest_path)

Downloads a file from the specified URL and saves it to the specified destination path.

Parameters
  • url (str) – The URL of the file to be downloaded.

  • dest_path (str) – The destination path to save the downloaded file to. Defaults to the user’s application data directory.

Returns

The absolute path of the downloaded file.

Return type

str

Raises

requests.exceptions.HTTPError – If there was an HTTP error during the request.

Note

This method checks if the compressed downloaded file type and extracts it.

Example:

download_file(url='https://example.com/data.zip', dest_path='data/')
sinatools.DataDownload.downloader.extract_tar(file_path, dest_path)

Extracts the contents of a tar.gz file to the specified destination path.

Parameters
  • file_path (str) – The path to the tar.gz file.

  • dest_path (str) – The destination path where the contents will be extracted.

Returns

The path to the extracted folder if successful, or None if extraction failed.

Return type

str

sinatools.DataDownload.downloader.extract_zip(file_path, extracted_folder_name)

Extracts the contents of a ZIP file to the specified folder.

Parameters
  • file_path (str) – The path to the ZIP file.

  • extracted_folder_name (str) – The name of the folder where the contents will be extracted.

Returns

None

sinatools.DataDownload.downloader.get_appdatadir()

This method checks if the directory exists and creates if it doesn’t. And returns the path to the directory where the application data is stored.

Example:

from sinatools.DataDownload import downloader

path = downloader.get_appdatadir()

Windows: 'C:/Users/<Username>/AppData/Roaming/sinatools'
MacOS: '/Users/<Username>/Library/Application Support/sinatools'
Linux: '/home/<Username>/.sinatools'
Google Colab: '/content/sinatools'