bug fixes
This commit is contained in:
		| @@ -85,10 +85,8 @@ class PDFDownloader: | ||||
|             # will be propagated to the saved file (dst) as well | ||||
|  | ||||
|         fname = article_object.fname_template | ||||
|         fname = ensure_unique(article_object.save_path, fname) | ||||
|         dst = os.path.join(article_object.save_path, fname) | ||||
|         if os.path.exists(dst): | ||||
|             fname = make_path_unique(fname) | ||||
|             dst = os.path.join(article_object.save_path, fname) | ||||
|  | ||||
|  | ||||
|         if url[-4:] == ".pdf": # calling the ususal pdf generation would not yield a nice pdf, just download it directly | ||||
| @@ -137,7 +135,6 @@ class PDFDownloader: | ||||
|  | ||||
|     def create_tmp_profile(self, full_profile_path: Path = Path(config["browser_profile_path"])) -> Path: | ||||
|         reduced_profile_path = Path(f"/tmp/firefox_profile_{uuid.uuid4()}") | ||||
|         print(reduced_profile_path, full_profile_path) | ||||
|         os.mkdir(reduced_profile_path) | ||||
|         # copy needed directories | ||||
|         dirs = ["extensions", "storage"] | ||||
| @@ -150,13 +147,20 @@ class PDFDownloader: | ||||
|             shutil.copy(full_profile_path / f, reduced_profile_path) | ||||
|          | ||||
|         folder_size = round(sum(p.stat().st_size for p in Path(reduced_profile_path).rglob('*')) / 1024 / 1024, 3) | ||||
|         self.logger.info(f"Generated temporary profile with size {folder_size} MB") | ||||
|         self.logger.info(f"Generated temporary profile at {reduced_profile_path} with size {folder_size} MB") | ||||
|         return reduced_profile_path | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
| def make_path_unique(path): | ||||
|     fname, ending = os.path.splitext(path) | ||||
|     fname += datetime.datetime.now().strftime("%d-%H%M%S") | ||||
|     return fname + ending | ||||
| def ensure_unique(path, fname): | ||||
|     fbase, ending = os.path.splitext(fname) | ||||
|  | ||||
|     exists = os.path.exists(os.path.join(path, fname)) | ||||
|     i = 1 | ||||
|     while exists: | ||||
|         fname = fbase + f" -- fetch {i}" + ending | ||||
|         i += 1 | ||||
|         exists = os.path.exists(os.path.join(path, fname)) | ||||
|      | ||||
|     return fname | ||||
|   | ||||
		Reference in New Issue
	
	Block a user