Allow to overwrite file when using bot.download_file method
This commit is contained in:
parent
3969794075
commit
a3b28bc1d6
@ -11,7 +11,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.9.11"
|
__version__ = "2.9.12"
|
||||||
__maintainer__ = "Davide Testa"
|
__maintainer__ = "Davide Testa"
|
||||||
__contact__ = "t.me/davte"
|
__contact__ = "t.me/davte"
|
||||||
|
|
||||||
|
@ -2127,7 +2127,8 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject):
|
|||||||
return sent_update
|
return sent_update
|
||||||
|
|
||||||
async def download_file(self, file_id,
|
async def download_file(self, file_id,
|
||||||
file_name=None, path=None):
|
file_name=None, path=None,
|
||||||
|
prevent_overwriting: bool = False):
|
||||||
"""Given a telegram `file_id`, download the related file.
|
"""Given a telegram `file_id`, download the related file.
|
||||||
|
|
||||||
Telegram may not preserve the original file name and MIME type: the
|
Telegram may not preserve the original file name and MIME type: the
|
||||||
@ -2151,6 +2152,7 @@ class Bot(TelegramBot, ObjectWithDatabase, MultiLanguageObject):
|
|||||||
if file_name is None:
|
if file_name is None:
|
||||||
file_name = get_secure_key(length=10)
|
file_name = get_secure_key(length=10)
|
||||||
file_complete_path = os.path.join(path, file_name)
|
file_complete_path = os.path.join(path, file_name)
|
||||||
|
if prevent_overwriting:
|
||||||
while os.path.exists(file_complete_path):
|
while os.path.exists(file_complete_path):
|
||||||
file_complete_path = file_complete_path + '1'
|
file_complete_path = file_complete_path + '1'
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user