From 6437b40682484eb3e309bb2adae55a64518596bc Mon Sep 17 00:00:00 2001 From: Kaya <95276965+kytpbs@users.noreply.github.com> Date: Wed, 7 Aug 2024 17:07:32 +0300 Subject: [PATCH] use cached result on twitter download if avaliable Oops forgot a single if check that would use the cached result instead --- src/twitter.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/twitter.py b/src/twitter.py index 4f5d00e..9f8b45f 100644 --- a/src/twitter.py +++ b/src/twitter.py @@ -27,6 +27,13 @@ def _download_video_from_link(url: str, filename: int | str, path: str | None = path = os.path.join("downloads", "twitter") os.makedirs(path, exist_ok=True) + filepath = os.path.join( + path, + f"{filename}.mp4", + ) + + if os.path.exists(filepath): + return filepath try: response = requests.get(url, timeout=30) @@ -34,10 +41,6 @@ def _download_video_from_link(url: str, filename: int | str, path: str | None = logging.error("Error while downloading tweet: %s", str(e)) return None - filepath = os.path.join( - path, - f"{filename}.mp4", - ) with open( filepath, "wb",