Queer European MD passionate about IT
Browse Source

Small improvement in `download_file` method

Generate new file name if no file name is provided; make sure it does 
not exist.
Davte 5 years ago
parent
commit
4abad7c423
2 changed files with 4 additions and 2 deletions
  1. 1 1
      davtelepot/__init__.py
  2. 3 1
      davtelepot/bot.py

+ 1 - 1
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"
 

+ 3 - 1
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)