From 4abad7c4230162c596bd20e1f9bea2aae0688ad9 Mon Sep 17 00:00:00 2001 From: Davte Date: Wed, 8 Jan 2020 10:30:47 +0100 Subject: [PATCH] Small improvement in `download_file` method Generate new file name if no file name is provided; make sure it does not exist. --- davtelepot/__init__.py | 2 +- davtelepot/bot.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/davtelepot/__init__.py b/davtelepot/__init__.py index 39b3a01..e303b44 100644 --- a/davtelepot/__init__.py +++ b/davtelepot/__init__.py @@ -14,7 +14,7 @@ __author__ = "Davide Testa" __email__ = "davide@davte.it" __credits__ = ["Marco Origlia", "Nick Lee @Nickoala"] __license__ = "GNU General Public License v3.0" -__version__ = "2.3.15" +__version__ = "2.3.16" __maintainer__ = "Davide Testa" __contact__ = "t.me/davte" diff --git a/davtelepot/bot.py b/davtelepot/bot.py index e217b0d..f88092e 100644 --- a/davtelepot/bot.py +++ b/davtelepot/bot.py @@ -1727,8 +1727,10 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject): mode='raw' ) path = path or self.path - if file_name is None: + while file_name is None: file_name = get_secure_key(length=10) + if os.path.exists(f"{path}/{file_name}"): + file_name = None try: with open(f"{path}/{file_name}", 'wb') as local_file: local_file.write(file_bytes)