Small improvement in download_file method

Generate new file name if no file name is provided; make sure it does 
not exist.
This commit is contained in:
Davte 2020-01-08 10:30:47 +01:00
parent 8565a96e15
commit 4abad7c423
2 changed files with 4 additions and 2 deletions

View File

@ -14,7 +14,7 @@ __author__ = "Davide Testa"
__email__ = "davide@davte.it" __email__ = "davide@davte.it"
__credits__ = ["Marco Origlia", "Nick Lee @Nickoala"] __credits__ = ["Marco Origlia", "Nick Lee @Nickoala"]
__license__ = "GNU General Public License v3.0" __license__ = "GNU General Public License v3.0"
__version__ = "2.3.15" __version__ = "2.3.16"
__maintainer__ = "Davide Testa" __maintainer__ = "Davide Testa"
__contact__ = "t.me/davte" __contact__ = "t.me/davte"

View File

@ -1727,8 +1727,10 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject):
mode='raw' mode='raw'
) )
path = path or self.path path = path or self.path
if file_name is None: while file_name is None:
file_name = get_secure_key(length=10) file_name = get_secure_key(length=10)
if os.path.exists(f"{path}/{file_name}"):
file_name = None
try: try:
with open(f"{path}/{file_name}", 'wb') as local_file: with open(f"{path}/{file_name}", 'wb') as local_file:
local_file.write(file_bytes) local_file.write(file_bytes)