Skip to content

Commit

Permalink
use cached result on twitter download if avaliable
Browse files Browse the repository at this point in the history
Oops forgot a single if check that would use the cached result instead
  • Loading branch information
kytpbs committed Aug 7, 2024
1 parent 35ab72f commit 6437b40
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,20 @@ 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)
except requests.exceptions.RequestException as e:
logging.error("Error while downloading tweet: %s", str(e))
return None

filepath = os.path.join(
path,
f"{filename}.mp4",
)
with open(
filepath,
"wb",
Expand Down

0 comments on commit 6437b40

Please sign in to comment.