From d9dfaaa68c363da51c5cfc011cf6f36acd0277df Mon Sep 17 00:00:00 2001 From: benny Date: Tue, 25 Apr 2023 12:11:12 +0300 Subject: [PATCH] preformence improvement --- .gitignore | 3 ++- download books in bulks.py | 11 +++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index b05ae27..f88e5bf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .vscode/ -venv/ \ No newline at end of file +venv/ +ignore/ \ No newline at end of file diff --git a/download books in bulks.py b/download books in bulks.py index c97bc32..3ba5452 100644 --- a/download books in bulks.py +++ b/download books in bulks.py @@ -76,7 +76,10 @@ def do_action_now(index: int): files = list(SOURCES[index]) for s in SOURCES[index]: if SOURCES[index][s]: - files[files.index(s)] = urllib3.PoolManager().request("GET", SOURCES[index][s]).data + if not os.path.exists(f"ignore/{files.index(s):04}.jpg"): + with open(f"ignore/{files.index(s):04}.jpg","wb") as F: + F.write(urllib3.PoolManager().request("GET", SOURCES[index][s]).data) + # files[files.index(s)] = urllib3.PoolManager().request("GET", SOURCES[index][s]).data return files # def check_and_act(index: int,last): @@ -110,15 +113,15 @@ def act_now(index: int, path: str = None): url_now = url_now[:url_now.find("#")+1] + save_first if SOURCES[index][last] and "" in SOURCES[index].values(): ACTS[index]._driver.get(url_now) - pages = do_action_now(index) + do_action_now(index) SOURCES[index][last] = "" else: - pages = do_action_now(index) + do_action_now(index) if SOURCES[index] and "" not in SOURCES[index].values(): couters += 1 pathus = f'{path}/{name}.pdf' if path else f"ignore/{name}/{name}.pdf" with open(pathus, "wb") as file: - file.write(img2pdf.convert(pages)) + file.write(img2pdf.convert(glob.glob(f"ignore/{name}/*jpg"))) ACTS[index]._driver.quit() remove_text(OLD_REMOVE[index]) treads -= 1