Download the specified file to the target folder. Parameters ---------- target_dir: str data save directory file_name: str dataset name, needs to endwith .zip, value from [rl_data.zip, csv_data_cn.zip, ...] may contain fol
(self, file_name: str, target_dir: [Path, str], delete_old: bool = True)
| 70 | p_bar.update(chunk_size) |
| 71 | |
| 72 | def download_data(self, file_name: str, target_dir: [Path, str], delete_old: bool = True): |
| 73 | """ |
| 74 | Download the specified file to the target folder. |
| 75 | |
| 76 | Parameters |
| 77 | ---------- |
| 78 | target_dir: str |
| 79 | data save directory |
| 80 | file_name: str |
| 81 | dataset name, needs to endwith .zip, value from [rl_data.zip, csv_data_cn.zip, ...] |
| 82 | may contain folder names, for example: v2/qlib_data_simple_cn_1d_latest.zip |
| 83 | delete_old: bool |
| 84 | delete an existing directory, by default True |
| 85 | |
| 86 | Examples |
| 87 | --------- |
| 88 | # get rl data |
| 89 | python get_data.py download_data --file_name rl_data.zip --target_dir ~/.qlib/qlib_data/rl_data |
| 90 | When this command is run, the data will be downloaded from this link: https://qlibpublic.blob.core.windows.net/data/default/stock_data/rl_data.zip?{token} |
| 91 | |
| 92 | # get cn csv data |
| 93 | python get_data.py download_data --file_name csv_data_cn.zip --target_dir ~/.qlib/csv_data/cn_data |
| 94 | When this command is run, the data will be downloaded from this link: https://qlibpublic.blob.core.windows.net/data/default/stock_data/csv_data_cn.zip?{token} |
| 95 | ------- |
| 96 | |
| 97 | """ |
| 98 | target_dir = Path(target_dir).expanduser() |
| 99 | target_dir.mkdir(exist_ok=True, parents=True) |
| 100 | # saved file name |
| 101 | _target_file_name = datetime.datetime.now().strftime("%Y%m%d%H%M%S") + "_" + os.path.basename(file_name) |
| 102 | target_path = target_dir.joinpath(_target_file_name) |
| 103 | |
| 104 | url = self.merge_remote_url(file_name) |
| 105 | self.download(url=url, target_path=target_path) |
| 106 | |
| 107 | self._unzip(target_path, target_dir, delete_old) |
| 108 | if self.delete_zip_file: |
| 109 | target_path.unlink() |
| 110 | |
| 111 | def check_dataset(self, file_name: str): |
| 112 | url = self.merge_remote_url(file_name) |