Similar to self.download_file(), except that you get to rename the file being downloaded to whatever you want.
(self, file_url, new_file_name, destination_folder=None)
| 8082 | self.__extra_actions.append(action) |
| 8083 | |
| 8084 | def save_file_as(self, file_url, new_file_name, destination_folder=None): |
| 8085 | """Similar to self.download_file(), except that you get to rename the |
| 8086 | file being downloaded to whatever you want.""" |
| 8087 | download_file_lock = fasteners.InterProcessLock( |
| 8088 | constants.MultiBrowser.DOWNLOAD_FILE_LOCK |
| 8089 | ) |
| 8090 | with download_file_lock: |
| 8091 | with suppress(Exception): |
| 8092 | shared_utils.make_writable( |
| 8093 | constants.MultiBrowser.DOWNLOAD_FILE_LOCK |
| 8094 | ) |
| 8095 | if not destination_folder: |
| 8096 | destination_folder = constants.Files.DOWNLOADS_FOLDER |
| 8097 | if not os.path.exists(destination_folder): |
| 8098 | os.makedirs(destination_folder) |
| 8099 | agent = self.get_user_agent() |
| 8100 | headers = {"user-agent": agent} |
| 8101 | page_utils._download_file_to( |
| 8102 | file_url, destination_folder, new_file_name, headers=headers |
| 8103 | ) |
| 8104 | |
| 8105 | def save_data_as(self, data, file_name, destination_folder=None): |
| 8106 | """Saves the data specified to the file specified. |
nothing calls this directly
no test coverage detected