def upload(
     yd,
     log,
     photo,
     local_path,
     chat_title,
 ):
     uploaded = False
     with open(local_path, "rb") as f:
         if not Chat.is_exists(photo.chat_id):
             try:
                 Chat.save_to_db(photo.chat_id, chat_title)
             except BaseException as e:
                 log.error('{0}'.format(e))
         yd_path = photo.get_yd_path(yd)
         if not yd.exists(yd_path):
             start = time.time()
             yd.upload(f, yd_path)
             end = time.time()
             log.info("YD uploaded: {0} ({1}s)".format(
                 yd_path, str(end - start)))
             if not Photo.is_exists(photo.chat_id, local_path):
                 db.session.add(photo)
                 db.session.commit()
                 log.info("DB added: " + yd_path)
             uploaded = True
     os.remove(local_path)
     return uploaded
 def init_chat(message):
     with app.app_context():
         if not is_initialized(message):
             if not Chat.is_exists(message.chat.id):
                 try:
                     ch = Chat.save_to_db(message.chat.id, message.chat.title)
                 except BaseException as e:
                     self.l.error('{0}'.format(e))
             ch.get_yd_folder(self.y)
 def is_initialized(message):
     with app.app_context():
         return Chat.is_exists(message.chat.id)