def process_telegram_data(data): try: logger.debug('receive data') logger.debug(data) type_list = ModelSetting.get('cache_save_type_list').split('|') type_list = Util.get_list_except_empty(type_list) if len(type_list) == 0 or data['t'] in type_list: ret = ModelOffcloud2Cache.add(data) if ret is not None: logger.debug('Offcloud2 %s append' % ret.name) if ModelSetting.get_bool( 'cache_receive_info_send_telegram'): msg = '😉 Offcloud2 캐쉬 정보 수신\n' msg += 'Type : %s\n' % data['t'] msg += '%s\n' % data['n'] from system.model import ModelSetting as SystemModelSetting ddns = SystemModelSetting.get('ddns') url = '%s/%s/api/cache_download?id=%s' % ( ddns, package_name, ret.id) if SystemModelSetting.get_bool('auth_use_apikey'): url += '&apikey=%s' % SystemModelSetting.get( 'auth_apikey') msg += '➕ 리모트 다운로드 추가\n<%s>' % url ToolBaseNotify.send_message( msg, message_id='offcloud2_cache_receive') except Exception as e: logger.error(e) logger.error(traceback.format_exc())
def start(bot_token): try: if TelegramBot.message_loop is None: TelegramBot.bot = Bot(bot_token) me = TelegramBot.bot.getMe() logger.debug('TelegramBot bot : %s', me) TelegramBot.message_loop = MessageLoop( TelegramBot.bot, TelegramBot.receive_callback) TelegramBot.message_loop.run_as_thread() ToolBaseNotify.send_message('텔레그램 메시지 수신을 시작합니다. %s' % (datetime.datetime.now())) TelegramBot.SUPER_BOT = Bot(TelegramBot.SUPER_TOKEN) if SystemModelSetting.get( 'ddns') == app.config['DEFINE']['MAIN_SERVER_URL']: logger.warning('ADMIN_TOKEN : %s ', TelegramBot.ADMIN_TOKEN) logger.warning('ADMIN_TOKEN : %s ', TelegramBot.ADMIN_TOKEN) logger.warning('ADMIN_TOKEN : %s ', TelegramBot.ADMIN_TOKEN) TelegramBot.ADMIN_BOT = Bot(TelegramBot.ADMIN_TOKEN) MessageLoop( TelegramBot.ADMIN_BOT, TelegramBot.super_receive_callback).run_as_thread() #TelegramBotHandle.super_sendMessage('관리봇이 텔레그램 메시지 수신을 시작하였습니다.', encryped=False) pass while TelegramBot.message_loop is not None: time.sleep(60 * 60) except Exception as exception: logger.error('Exception:%s', exception) logger.error(traceback.format_exc())
def process_telegram_data(self, data, target=None): try: ret = ModelItem.process_telegram_data(data) logger.debug(data) #ret = None if ret is not None: if ModelSetting.get_bool('receive_send_notify'): msg = '😉 AV 정보 수신\n' msg += '제목 : [%s] %s (%s)\n' % (ret.code, ret.title, ret.date) msg += '파일 : %s\n' % ret.filename msg += '폴더 : %s\n' % ret.dirname msg += '크기 : %s\n' % Util.sizeof_fmt(ret.total_size) url = '%s/%s/api/%s/add_download?id=%s' % (SystemModelSetting.get('ddns'), package_name, self.name, ret.id) if SystemModelSetting.get_bool('auth_use_apikey'): url += '&apikey=%s' % SystemModelSetting.get('auth_apikey') if app.config['config']['is_server']: msg += '\n' + ret.magnet + '\n' else: msg += '\n➕ 다운로드 추가\n<%s>\n' % url #msg += '\n➕ 다운로드 추가\n<%s>\n' % url poster = ret.poster if ModelSetting.get_bool('show_poster_notify') else None ToolBaseNotify.send_message(msg, image_url=poster, message_id='bot_downloader_av_receive') self.invoke() try: if app.config['config']['is_server']: from tool_expand import TorrentProcess TorrentProcess.receive_new_data(ret, package_name) except: pass except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc())
def send_telegram_message(item): try: msg = '😉 봇 다운로드 - AV 처리결과\n' msg += '제목 : [%s] %s (%s)\n' % (item.code, item.title, item.date) msg += '파일 : %s\n' % item.filename if item.download_status == 'true': status_str = '✔조건일치 - 요청' elif item.download_status == 'false': status_str = '⛔패스 ' elif item.download_status == 'no': status_str = '자동 다운로드 사용안함' elif item.download_status == 'true_only_status': status_str = '✔조건일치 - 상태만' elif item.download_status == 'false_only_status': status_str = '⛔조건불일치 - 상태만' msg += '결과 : %s\n' % status_str msg += '%s/%s/list\n' % (SystemModelSetting.get('ddns'), package_name) msg += '로그\n' + item.log ToolBaseNotify.send_message(msg, message_id='bot_downloader_av_result') except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc())
def process_send_alarm(message): try: bot_id = ModelSetting.get('bot_id') ToolBaseNotify.send_message(message, message_id=bot_id) except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc())
def receive_scan_result(id, filename): try: import plex #with db.session.no_autoflush: logger.debug('Receive Scan Completed : %s-%s', id, filename) #modelfile = db.session.query(ModelKtvFile).filter_by(id=int(id)).with_for_update().first() modelfile = db.session.query(ModelKtvFile).filter_by( id=int(id)).first() if modelfile is not None: modelfile.scan_status = 3 modelfile.scan_time = datetime.now() #if modelfile.plex_show_id == -1: plex.Logic.get_section_id(modelfile, more=True) #db.session.commit() if scheduler.is_running('ktv_process'): Logic.plex_update_list.append(modelfile) logger.debug('>> plex_update_list insert!!') else: db.session.add(modelfile) db.session.commit() logger.debug('>> direct commit!!') if ModelSetting.query.filter_by( key='telegram').first().value == 'True': text = '<PLEX 스캔 완료 - KTV>\n%s\n\n%s' % ( modelfile.filename, modelfile.plex_part) ToolBaseNotify.send_message( text, message_id='fileprocess_ktv_scan_completed') except Exception as exception: logger.debug('>>>>> receive_scan_result') logger.error('Exception:%s', exception) logger.error(traceback.format_exc())
def process_ajax(sub, req): try: if sub == 'telegram_test': ret = ToolBaseNotify.send_telegram_message( req.form['text'], bot_token=req.form['bot_token'], chat_id=req.form['chat_id']) return jsonify(ret) elif sub == 'discord_test': ret = ToolBaseNotify.send_discord_message( req.form['text'], webhook_url=req.form['url']) return jsonify(ret) elif sub == 'advanced_test': ret = ToolBaseNotify.send_advanced_message( req.form['text'], policy=req.form['policy'], message_id=req.form['message_id']) return jsonify(ret) elif sub == 'scheduler': go = request.form['scheduler'] logger.debug('scheduler :%s', go) if go == 'true': SystemLogicTelegramBot.scheduler_start() else: SystemLogicTelegramBot.scheduler_stop() return jsonify(go) except Exception as exception: logger.error('Exception:%s', exception) logger.error(traceback.format_exc()) return jsonify('exception')
def receive_callback(msg): try: content_type, chat_type, chat_id = glance(msg) #logger.debug(chat_id) try: if content_type == 'text' and msg['text'][0] == '^': if SystemModelSetting.get_bool('telegram_resend'): chat_list = SystemModelSetting.get_list( 'telegram_resend_chat_id') #logger.debug(chat_list) if str(chat_id) not in chat_list: for c in chat_list: ToolBaseNotify.send_telegram_message( msg['text'], SystemModelSetting.get( 'telegram_bot_token'), chat_id=c) except Exception as exception: logger.error('Exception:%s', exception) logger.error(traceback.format_exc()) if content_type == 'text': text = msg['text'] if msg['text'] == '/bot': text = json.dumps(TelegramBot.bot.getMe(), indent=2) TelegramBot.bot.sendMessage(chat_id, text) elif msg['text'] == '/me': text = json.dumps(msg, indent=2) TelegramBot.bot.sendMessage(chat_id, text) elif msg['text'][0] == '^': TelegramBot.process_receive_data(msg['text'][1:]) elif msg['text'] == '/call': data = TelegramBot.bot.getMe() #logger.debug(data) from framework import version text = 'call : %s / %s / %s / %s / %s / %s' % ( data['username'], data['id'], data['first_name'], version, SystemModelSetting.get('sjva_me_user_id'), SystemModelSetting.get('sjva_id')) TelegramBot.bot.sendMessage(chat_id, text) elif msg['text'].startswith('call'): logger.debug(msg['text']) except Exception as exception: logger.error('Exception:%s', exception) logger.error(traceback.format_exc())
def process_telegram_data(self, data, target=None): try: ret = ModelBotDownloaderKtvItem.process_telegram_data(data) #logger.debug(ret) if ret is not None: if ModelSetting.get_bool('receive_info_send_telegram'): msg = '😉 TV 정보 수신\n' msg += '제목 : %s\n' % data['filename'] if ret is None: msg += '중복 마그넷입니다.' #TelegramHandle.sendMessage(msg) else: url = '%s/%s/api/%s/add_download?url=%s' % ( SystemModelSetting.get('ddns'), package_name, self.name, ret.magnet) if SystemModelSetting.get_bool('auth_use_apikey'): url += '&apikey=%s' % SystemModelSetting.get( 'auth_apikey') if app.config['config']['is_server']: msg += '\n' + ret.magnet + '\n' else: msg += '\n➕ 다운로드 추가\n<%s>\n' % url try: if ret.daum_id is not None: url = 'https://search.daum.net/search?w=tv&q=%s&irk=%s&irt=tv-program&DA=TVP' % ( py_urllib.quote( ret.daum_title.encode('utf8')), ret.daum_id) msg += '\n● Daum 정보\n%s' % url except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc()) ToolBaseNotify.send_message( msg, image_url=ret.daum_poster_url, message_id='bot_downloader_ktv_receive') self.invoke() try: if app.config['config']['is_server']: from tool_expand import TorrentProcess TorrentProcess.receive_new_data(ret, package_name) except: pass except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc())
def send_telegram(where, title): try: if LogicNormal.pre_telegram_title == title: return else: LogicNormal.pre_telegram_title = title if where == '0': msg = '트랜스미션' elif where == '1': msg = '다운로드스테이션' elif where == '2': msg = '큐빗토렌트' elif where == '3': msg = 'aria2' msg += '\n%s 다운로드 완료' % title ToolBaseNotify.send_message(msg, message_id='downloader_completed_remove') except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc())
def process_ajax(sub, req): try: if sub == 'telegram_test': ret = ToolBaseNotify.send_telegram_message( req.form['text'], bot_token=req.form['bot_token'], chat_id=req.form['chat_id']) return jsonify(ret) elif sub == 'discord_test': ret = ToolBaseNotify.send_discord_message( req.form['text'], webhook_url=req.form['url']) return jsonify(ret) elif sub == 'advanced_test': ret = ToolBaseNotify.send_advanced_message( req.form['text'], policy=req.form['policy'], message_id=req.form['message_id']) return jsonify(ret) except Exception as exception: logger.error('Exception:%s', exception) logger.error(traceback.format_exc()) return jsonify('exception')
def process_telegram_data(data): try: ret = ModelMovieItem.process_telegram_data(data) #logger.debug('telegram bot receive. is exist : %s', ret) if ret is not None: if ModelSetting.get_bool('receive_info_send_telegram'): msg = '😉 영화 정보 수신\n' msg += '제목 : %s (%s)\n' % (ret.movie_title, ret.movie_year) msg += '파일 : %s\n' % ret.filename url = '%s/%s/api/add_download?id=%s' % (SystemModelSetting.get('ddns'), package_name, ret.id) if SystemModelSetting.get_bool('auth_use_apikey'): url += '&apikey=%s' % SystemModelSetting.get('auth_apikey') if app.config['config']['is_server']: msg += '\n' + ret.magnet + '\n' else: msg += '\n➕ 다운로드 추가\n<%s>\n' % url #msg += '\n➕ 다운로드 추가\n<%s>\n' % url try: if ret.movie_title is not None: if ret.movie_target == 'imdb': url = 'https://www.imdb.com/title/%s' % ret.movie_id msg += '\n● IMDB 정보\n%s' % url else: url = 'https://movie.daum.net/moviedb/main?movieId=%s' % (ret.movie_id) msg += '\n● Daum 정보\n%s' % url except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc()) ToolBaseNotify.send_message(msg, image_url=ret.daum_poster, message_id='bot_downloader_movie_receive') LogicNormal.invoke() try: if app.config['config']['is_server']: from tool_expand import TorrentProcess TorrentProcess.receive_new_data(ret, package_name) except: pass except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc())
def db_save(data, dest, match_type, is_moved): telegram_flag = ModelSetting.get_bool('telegram') try: entity = {} entity['name'] = data['search_name'] entity['fileName'] = data['name'] entity['dirName'] = data['fullPath'] entity['targetPath'] = dest entity['match_type'] = match_type if is_moved: entity['is_moved'] = 1 else: entity['is_moved'] = 0 ModelItem.save_as_dict(entity) if telegram_flag == 1: text = u'파일정리\n [%s] %s -> %s\n' % (match_type, data['fullPath'], dest) #import framework.common.notify as Notify #Notify.send_message(text, message_id = 'files_move_result') from tool_base import ToolBaseNotify ToolBaseNotify.send_message(text, message_id = 'files_move_result') except Exception as e: logger.error('Exxception:%s', e) logger.error(traceback.format_exc())
def send_telegram_message(self, item): try: telegram_log = '😉 봇 다운로드 - TV\n' telegram_log += '정보 : %s (%s), %s회, %s\n' % (item.daum_title, item.daum_genre, item.filename_number, item.filename_date) if item.download_status.startswith('True'): status_str = '✔요청 ' elif item.download_status.startswith('False'): status_str = '⛔패스 ' else: status_str = '🕛대기 ' if item.plex_key is not None: if item.plex_key.startswith('P'): status_str += '(PLEX 프로그램⭕ 에피소드❌) ' elif item.plex_key.startswith('E'): status_str += '(PLEX 프로그램⭕ 에피소드⭕) ' else: status_str += '(PLEX 프로그램❌) ' if item.download_status == 'True_by_plex_in_lib_multi_epi': status_str += '에피소드 멀티파일' elif item.download_status == 'False_by_plex_in_one_epi': status_str += '에피소드 이미 있음' elif item.download_status == 'True_by_plex_in_lib_no_epi': status_str += '에피소드 없음' elif item.download_status == 'True_blacklist': status_str += '블랙리스트에 없음' elif item.download_status == 'False_whitelist': status_str += '화이트리스트에 없음' elif item.download_status == 'False_except_program': status_str += '블랙리스트' elif item.download_status == 'True_whitelist_program': status_str += '화이트리스트' elif item.download_status == 'True_whitelist_first_epi': status_str += '첫번째 에피소드' elif item.download_status == 'False_no_meta': status_str += 'Daum 검색 실패' elif item.download_status == 'False_except_genre': status_str += '블랙리스트 장르' elif item.download_status == 'True_whitelist_genre': status_str += '화이트리스트 장르' elif item.download_status == 'False_not_allow_duplicate_episode': status_str += '중복 제외' elif item.download_status == 'False_exist_download_quality': status_str += '동일 화질 받음' elif item.download_status == 'False_not_match_condition_quality': status_str += '화질 조건 불일치' elif item.download_status == 'False_not_match_condition_include_keyword': status_str += '단어 포함 조건' elif item.download_status == 'False_match_condition_except_keyword': status_str += '단어 제외 조건' telegram_log += '결과 : %s\n' % status_str telegram_log += '파일명 : %s\n' % item.filename telegram_log += '%s/%s/list\n' % (SystemModelSetting.get('ddns'), package_name) #telegram_log += item.download_status + '\n' telegram_log += '로그\n' + item.log ToolBaseNotify.send_message(telegram_log, message_id='bot_downloader_ktv_result') except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc())
def process_download_file(self): setting_list = Util.db_list_to_dict( db.session.query(ModelSetting).all()) Logic._DOWNLOAD_PATH = setting_list['download_path'] except_partial = setting_list['except_partial'].split(',') except_genre_remove_epi_number = [ x.strip() for x in setting_list['except_genre_remove_epi_number'].split(',') ] if '' in except_genre_remove_epi_number: except_genre_remove_epi_number.remove('') library_list = db.session.query(ModelKtvLibrary).all() Logic._LIBRARY_ROOT_LIST = [] for item in library_list: if item.library_type == 0: drive_type = EntityLibraryPathRoot.DriveType.LOCAL else: drive_type = EntityLibraryPathRoot.DriveType.RCLONE lib = EntityLibraryPathRoot(drive_type=drive_type, mount_path=item.library_path, rclone_path=item.rclone_path, depth=2, replace_for_plex=[ item.replace_for_plex_source, item.replace_for_plex_target ]) Logic._LIBRARY_ROOT_LIST.append(lib) dir_list = None path = Logic._DOWNLOAD_PATH list_ = os.listdir(Logic._DOWNLOAD_PATH) logger.debug('process_download_file 2') logger.debug('list : %s', len(list_)) # rclone 시작이 필요한가.. flag_rclone_start = False for var in list_: try: #with db.session.no_autoflush: if True: abspath = os.path.join(path, var) telegram_log = None entity = None if os.path.isfile(abspath): if Logic.check_except_partial(var, except_partial): continue telegram_log = package_name + '\n%s\n' % abspath if dir_list is None: logger.debug('process_download_file') # 방송이름 목록 dir_list = Logic._make_dir_list() logger.debug('process_download_file 1') logger.debug('===================================') logger.debug('File Process: %s', var) # 방송용 파일이 아니면 entity = EntityShow(var, nd_download_path=path, except_genre_remove_epi_number= except_genre_remove_epi_number) if entity.video_type == EntityShow.VideoType.KOREA_TV: logger.debug('<Move>') _find_dir = Logic._get_find_dir(dir_list, entity) if len(_find_dir) == 1: entity.set_find_library_path(_find_dir[0]) logger.debug(' - 하나의 폴더 선택됨 : %s', _find_dir[0].abspath) entity.move_file() # 2019-09-01 if entity.scan_status == EntityShow.ScanStatus.MOVED and entity.nd_find_library_path.entity_library_root.drive_type == EntityLibraryPathRoot.DriveType.LOCAL: if app.config['config']['use_celery']: self.update_state( state='PROGRESS', meta={ 'filename': entity.move_abspath_local }) else: Logic.send_to_listener( entity.move_abspath_local) elif entity.scan_status == EntityShow.ScanStatus.MOVED and entity.nd_find_library_path.entity_library_root.drive_type == EntityLibraryPathRoot.DriveType.RCLONE: if app.config['config']['use_celery']: self.update_state( state='PROGRESS', meta={ 'filename': entity.move_abspath_cloud }) else: Logic.send_to_listener( entity.move_abspath_cloud) entity.modelfile = ModelKtvFile.create(entity) logger.debug(entity.log) # ID를 보내야하기 때문에 commit db.session.add(entity.modelfile) db.session.commit() if entity.scan_status == EntityShow.ScanStatus.MOVED: try: import plex plex.Logic.send_scan_command( entity.modelfile, package_name) except Exception as exception: logger.debug('NOT IMPORT PLEX!!') db.session.add(entity.modelfile) db.session.commit() if entity.move_type == EntityLibraryPathRoot.DriveType.RCLONE: flag_rclone_start = True elif len(_find_dir) > 1: logger.debug(' - 선택된 폴더가 2개 이상') logger.debug(' %s', _find_dir[0].abspath) logger.debug(' %s', _find_dir[1].abspath) entity.log += '<파일이동>\n' entity.log += '선택된 폴더 %s개\n' % (len(_find_dir)) entity.log += ' %s\n' % _find_dir[0].abspath entity.log += ' %s\n' % _find_dir[1].abspath tmp = os.path.join( Logic._DOWNLOAD_PATH, setting_list['manual_folder_name']) if not os.path.isdir(tmp): os.mkdir(tmp) if os.path.exists(os.path.join(tmp, var)): os.remove(os.path.join(tmp, var)) shutil.move(abspath, tmp) if app.config['config']['use_celery']: self.update_state(state='PROGRESS', meta={ 'filename': os.path.join( tmp, var) }) else: Logic.send_to_listener( os.path.join(tmp, var)) entity.log += ' %s 이동\n' % tmp elif not _find_dir: #continue logger.debug(' - 선택된 폴더 없음') entity.log += '<파일이동>\n' entity.log += '선택된 폴더 없음\n' flag_move = False if entity.daum_info is None: #if FileManagerSetting.HOW_TO_PROCESS_NO_DAUM_FILE == 'MOVE_ON_NOMETA_DIR_IN_DOWNLOAD_DIR': # tmp = os.path.join(Logic._DOWNLOAD_PATH, self._NO_DAUM_INFO_MOVE_DIRECTORY_NAME ) # if not os.path.isdir(tmp): # os.mkdir(tmp) # shutil.move(abspath, tmp) # flag_move = True #elif FileManagerSetting.HOW_TO_PROCESS_NO_DAUM_FILE == 'PROCESS_LIKE_AS_GENRE': #daum = EntityDaumTV(-1) try: import daum_tv daum = daum_tv.ModelDaumTVShow(-1) daum.genre = setting_list[ 'no_daum_folder_name'] daum.title = entity.filename_name except Exception as exception: logger.error('Exception:%s', exception) logger.error(traceback.format_exc()) daum = None entity.daum_info = daum if flag_move == False and entity.daum_info: flag_search = False for library_root in Logic._LIBRARY_ROOT_LIST: for _ in library_root.get_genre_list(): if _ == entity.daum_info.genre: #폴더만 만들어주고 다음번에 이동. 첫번째 선택된곳만 tmp = os.path.join( library_root.mount_path, _, Util. change_text_for_use_filename( entity.daum_info.title) ) if not os.path.isdir(tmp): logger.debug( 'mkdir:%s', tmp) os.mkdir(tmp) entity.log += '폴더생성 : %s\n' % tmp logger.debug( ' * 장르:%s [%s] 폴더 생성. 다음 탐색시 이동', _, tmp) flag_search = True break if flag_search: break if not flag_search: logger.debug(' * 장르:%s 없음.', entity.daum_info.genre) # TODO 옵션 # 로컬에 장르 만든다 """ _ = os.path.join(self._DOWNLOAD_PATH, 'tmp') if not os.path.isdir(_): os.mkdir(_) """ # 다음번에 방송명 폴더를 만든다??? _ = os.path.join( Logic._LIBRARY_ROOT_LIST[0]. mount_path, entity.daum_info.genre) if not os.path.isdir(_): os.mkdir(_) entity.log += '장르 폴더생성 : %s\n' % _ telegram_log += entity.log logger.debug('===================================') # 처리하지 못하는 포멧의 파일 else: tmp = os.path.join( Logic._DOWNLOAD_PATH, setting_list['not_ktv_move_folder_name']) if not os.path.isdir(tmp): os.mkdir(tmp) if os.path.exists(os.path.join(tmp, var)): os.remove(os.path.join(tmp, var)) shutil.move(abspath, tmp) if app.config['config']['use_celery']: self.update_state( state='PROGRESS', meta={'filename': os.path.join(tmp, var)}) else: Logic.send_to_listener(os.path.join(tmp, var)) telegram_log += '처리하지 못하는 파일 형식\n이동:%s\n' % tmp else: #폴더 tmp = var + '.mp4' match_flag = False for regex in EntityShow._REGEX_FILENAME: match = re.compile(regex).match(tmp) if match: match_flag = True break if match_flag: try: childs = os.listdir(abspath) # 모두 파일인 경우에만 처리 # 2019-07-13 for c in childs: if os.path.isdir(os.path.join(abspath, c)): continue for c in childs: tmp = os.path.join(abspath, c) if os.stat(tmp).st_size < 1000000: os.remove(tmp) else: if os.path.exists(os.path.join( path, c)): if os.stat( os.path.join(path, c) ).st_size >= os.stat(tmp).st_size: os.remove(tmp) else: os.remove(os.path.join( path, c)) shutil.move(tmp, path) else: shutil.move(tmp, path) shutil.rmtree(abspath) except Exception as exception: logger.error('Exception:%s', exception) logger.error(traceback.format_exc()) except Exception as exception: try: db.session.rollback() logger.debug( 'ROLLBACK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!') except: logger.debug('>>>>>>>>>>>>>>>>>>>>>>>>>>') logger.error('Exception:%s', exception) logger.error(traceback.format_exc()) finally: try: if ModelSetting.query.filter_by(key='telegram').first( ).value == 'True' and telegram_log is not None: img = None if entity is not None and entity.daum_info is not None and entity.daum_info.poster_url is not None: img = entity.daum_info.poster_url ToolBaseNotify.send_message( telegram_log, image_url=img, message_id='fileprocess_ktv_result') except Exception as exception: logger.error('Exception:%s', exception) logger.error(traceback.format_exc()) logger.debug('flag_rclone_start : %s', flag_rclone_start) #self.update_state(state='PROGRESS',meta={'flag_rclone_start':flag_rclone_start}) #if flag_rclone_start: # scheduler.execute_job('rclone') Logic.check_library_completed() return flag_rclone_start