Downloading files
- class oceanai.modules.lab.download.DownloadMessages(lang: str = 'ru', color_simple: str = '#666', color_info: str = '#1776D2', color_err: str = '#FF0000', color_true: str = '#008001', bold_text: bool = True, text_runtime: str = '', num_to_df_display: int = 30)[source]
Bases:
UnzipClass for messages
- Parameters:
lang (str) – See
langcolor_simple (str) – See
color_simplecolor_info (str) – See
color_infocolor_err (str) – See
color_errcolor_true (str) – See
color_truebold_text (bool) – See
bold_textnum_to_df_display (int) – See
num_to_df_displaytext_runtime (str) – See
text_runtime
- class oceanai.modules.lab.download.Download(lang: str = 'ru', color_simple: str = '#666', color_info: str = '#1776D2', color_err: str = '#FF0000', color_true: str = '#008001', bold_text: bool = True, text_runtime: str = '', num_to_df_display: int = 30)[source]
Bases:
DownloadMessagesClass for downloading files
- Parameters:
lang (str) – See
langcolor_simple (str) – See
color_simplecolor_info (str) – See
color_infocolor_err (str) – See
color_errcolor_true (str) – See
color_truebold_text (bool) – See
bold_textnum_to_df_display (int) – See
num_to_df_displaytext_runtime (str) – See
text_runtime
- __progressbar_download_file_from_url(url_filename: str, progress: float, clear_out: bool = True, last: bool = False, out: bool = True) None
File download progress bar from URL
Note
private method
- Parameters:
url_filename (str) – Path to file
progress (float) – Percent complete (from 0.0 to 100.0)
clear_out (bool) – Clearing the output area
last (bool) – Replacing the last message
out (bool) – Display
- Returns:
None
- Return type:
None
Examples
True – 1 –
In [1]:1import numpy as np 2from oceanai.modules.lab.download import Download 3 4download = Download(lang = 'en') 5 6for progress in np.arange(0., 101, 25): 7 download._Download__progressbar_download_file_from_url( 8 url_filename = 'https://clck.ru/32Nwdk', 9 progress = float(progress), 10 clear_out = False, 11 last = False, out = True 12 )
[1]:1[2022-10-16 16:58:51] File download "https://clck.ru/32Nwdk" (0.0%) ... 2 3[2022-10-16 16:58:51] File download "https://clck.ru/32Nwdk" (25.0%) ... 4 5[2022-10-16 16:58:51] File download "https://clck.ru/32Nwdk" (50.0%) ... 6 7[2022-10-16 16:58:51] File download "https://clck.ru/32Nwdk" (75.0%) ... 8 9[2022-10-16 16:58:51] File download "https://clck.ru/32Nwdk" (100.0%) ...
– 2 –
In [2]:1import numpy as np 2from oceanai.modules.lab.download import Download 3 4download = Download(lang = 'en') 5 6for progress in np.arange(0., 101, 25): 7 download._Download__progressbar_download_file_from_url( 8 url_filename = 'https://clck.ru/32Nwdk', 9 progress = float(progress), 10 clear_out = True, 11 last = True, out = True 12 )
[2]:1[2022-10-16 16:59:41] File download "https://clck.ru/32Nwdk" (100.0%) ...
Error – 1 –
In [3]:1import numpy as np 2from oceanai.modules.lab.download import Download 3 4download = Download(lang = 'en') 5 6for progress in np.arange(0., 101, 25): 7 download._Download__progressbar_download_file_from_url( 8 url_filename = 'https://clck.ru/32Nwdk', 9 progress = 101, 10 clear_out = True, 11 last = False, out = True 12 )
[3]:1[2022-10-16 17:00:11] Invalid argument types or values in "Download.__progressbar_download_file_from_url" ...
- _download_file_from_url(url: str, force_reload: bool = True, out: bool = True, runtime: bool = True, run: bool = True) int[source]
Downloading file from URL (without clearing message output history in Jupyter cell)
Note
protected method
- Parameters:
url (str) – Full path to the file
force_reload (bool) – Force a file download from the network
out (bool) – Display
runtime (bool) – Runtime count
run (bool) – Execution blocking
- Returns:
Response status code:
200- File downloaded400- Error validating arguments403- Run blocked by user404- Failed to download file
- Return type:
int
Examples
True – 1 –
In [1]:1from oceanai.modules.lab.download import Download 2 3download = Download() 4 5download.path_to_save_ = './models' 6download.chunk_size_ = 2000000 7 8res_download_file_from_url = download._download_file_from_url( 9 url = 'https://download.sberdisk.ru/download/file/400635799?token=MMRrak8fMsyzxLE&filename=weights_2022-05-05_11-27-55.h5', 10 force_reload = True, 11 out = True, 12 runtime = True, 13 run = True 14) 15res_download_file_from_url
[1]:1[2022-10-16 20:23:25] File download "weights_2022-05-05_11-27-55.h5" (100.0%) ... 2 3--- Runtime: 0.373 сек. --- 4 5200
– 2 –
In [2]:1from oceanai.modules.lab.download import Download 2 3download = Download(lang = 'en') 4 5download.path_to_save_ = './models' 6download.chunk_size_ = 2000000 7 8res_download_file_from_url = download._download_file_from_url( 9 url = 'https://clck.ru/32Nwdk', 10 force_reload = True, 11 out = True, 12 runtime = True, 13 run = False 14) 15res_download_file_from_url
[2]:1[2022-10-16 19:33:05] Run blocked by user ... 2 3403
Errors – 1 –
In [3]:1from oceanai.modules.lab.download import Download 2 3download = Download(lang = 'en') 4 5download.path_to_save_ = './models' 6download.chunk_size_ = 2000000 7 8res_download_file_from_url = download._download_file_from_url( 9 url = 1, 10 force_reload = True, 11 out = True, 12 runtime = True, 13 run = True 14) 15res_download_file_from_url
[3]:1[2022-10-16 19:33:01] Invalid argument types or values in "Download._download_file_from_url" ... 2 3400
– 2 –
In [4]:1from oceanai.modules.lab.download import Download 2 3download = Download(lang = 'en') 4 5download.path_to_save_ = './models' 6download.chunk_size_ = 2000000 7 8res_download_file_from_url = download._download_file_from_url( 9 url = 'https://', 10 force_reload = True, 11 out = True, 12 runtime = True, 13 run = True 14) 15res_download_file_from_url
[4]:1[2022-10-16 19:33:10] Something went wrong ... the specified URL could not be processed ... 2 3 File: /Users/dl/GitHub/oceanai/oceanai/modules/lab/download.py 4 Line: 257 5 Method: _download_file_from_url 6 Error type: InvalidURL 7 8--- Runtime: 0.061 сек. --- 9 10404
– 3 –
In [5]:1from oceanai.modules.lab.download import Download 2 3download = Download(lang = 'en') 4 5download.path_to_save_ = './models' 6download.chunk_size_ = 2000000 7 8res_download_file_from_url = download._download_file_from_url( 9 url = 'https://www.iconfinder.com/icons/4375050/download/svg/4096', 10 force_reload = True, 11 out = True, 12 runtime = True, 13 run = True 14) 15res_download_file_from_url
[5]:1[2022-10-16 19:33:15] File download "4375050_logo_python_icon.svg" 2 3[2022-10-16 19:33:15] Something went wrong ... Download file size not defined ... 4 5 File: /Users/dl/GitHub/oceanai/oceanai/modules/lab/download.py 6 Line: 324 7 Method: _download_file_from_url 8 Error type: InvalidContentLength 9 10--- Runtime: 0.386 сек. --- 11 12404
- download_file_from_url(url: str, force_reload: bool = True, out: bool = True, runtime: bool = True, run: bool = True) int[source]
Downloading a file from a URL
- Parameters:
url (str) – Full path to the file
force_reload (bool) – Force a file download from the network
out (bool) – Display
runtime (bool) – Runtime count
run (bool) – Execution blocking
- Returns:
Response status code:
200- File downloaded400- Error validating arguments403- Run blocked by user404- Failed to download file
- Return type:
int