def _http_query(self, query, timeout=None): """ Query Transmission through HTTP. """ headers = {'x-transmission-session-id': str(self.session_id)} result = {} request_count = 0 if timeout is None: timeout = self._query_timeout while True: LOGGER.debug(json.dumps({'url': self.url, 'headers': headers, 'query': query, 'timeout': timeout}, indent=2)) try: result = self.http_handler.request(self.url, query, headers, timeout) break except HTTPHandlerError as error: if error.code == 409: LOGGER.info('Server responded with 409, trying to set session-id.') if request_count > 1: raise TransmissionError('Session ID negotiation failed.', error) session_id = None for key in list(error.headers.keys()): if key.lower() == 'x-transmission-session-id': session_id = error.headers[key] self.session_id = session_id headers = {'x-transmission-session-id': str(self.session_id)} if session_id is None: debug_httperror(error) raise TransmissionError('Unknown conflict.', error) else: debug_httperror(error) raise TransmissionError('Request failed.', error) request_count += 1 return result
async def service_msg(client, message): if message.service == 'voice_chat_started': Config.IS_ACTIVE = True k = scheduler.get_job(str(Config.CHAT), jobstore=None) #scheduled records if k: await start_record_stream() LOGGER.info("Resuming recording..") elif Config.WAS_RECORDING: LOGGER.info( "Previous recording was ended unexpectedly, Now resuming recordings." ) await start_record_stream() #for unscheduled a = await client.send( GetFullChannel(channel=(await client.resolve_peer(Config.CHAT)))) if a.full_chat.call is not None: Config.CURRENT_CALL = a.full_chat.call.id LOGGER.info("Voice chat started.") await sync_to_db() elif message.service == 'voice_chat_scheduled': LOGGER.info("VoiceChat Scheduled") Config.IS_ACTIVE = False Config.HAS_SCHEDULE = True await sync_to_db() elif message.service == 'voice_chat_ended': Config.IS_ACTIVE = False LOGGER.info("Voicechat ended") Config.CURRENT_CALL = None if Config.IS_RECORDING: Config.WAS_RECORDING = True await stop_recording() await sync_to_db() else: pass
def json_pack(snippets_dir, video_name, frame_width, frame_height, label='unknown', label_index=-1): sequence_info = [] p = Path(snippets_dir) LOGGER.info(path) for path in p.glob(video_name+'*.json'): json_path = str(path) LOGGER.info(path) frame_id = int(path.stem.split('_')[-2]) frame_data = {'frame_index': frame_id} data = json.load(open(json_path)) skeletons = [] for person in data['people']: score, coordinates = [], [] skeleton = {} keypoints = person['pose_keypoints_2d'] for i in range(0, len(keypoints), 3): coordinates += [keypoints[i]/frame_width, keypoints[i + 1]/frame_height] score += [keypoints[i + 2]] skeleton['pose'] = coordinates skeleton['score'] = score skeletons += [skeleton] frame_data['skeleton'] = skeletons sequence_info += [frame_data] video_info = dict() video_info['data'] = sequence_info video_info['label'] = label video_info['label_index'] = label_index return video_info
def _http_query(self, query, timeout=None): """ Query Transmission through HTTP. """ headers = {'x-transmission-session-id': str(self.session_id)} result = {} request_count = 0 if timeout is None: timeout = self._query_timeout while True: LOGGER.debug( json.dumps({'url': self.url, 'headers': headers, 'query': query, 'timeout': timeout}, indent=2)) try: result = self.http_handler.request(self.url, query, headers, timeout) break except HTTPHandlerError as error: if error.code == 409: LOGGER.info('Server responded with 409, trying to set session-id.') if request_count > 1: raise TransmissionError('piSession ID negotiation failed.', error) session_id = None for key in list(error.headers.keys()): if key.lower() == 'x-transmission-session-id': session_id = error.headers[key] self.session_id = session_id headers = {'x-transmission-session-id': str(self.session_id)} if session_id is None: debug_httperror(error) raise TransmissionError('Unknown conflict.', error) else: debug_httperror(error) raise TransmissionError('Request failed.', error) request_count += 1 return result
def load_config(output_path): config_file = os.path.join(output_path, 'config.ini') config = configparser.ConfigParser() if os.path.exists(config_file): config.read(config_file) else: config.read_dict({ 'DB': { 'host': 'localhost', 'user': '******', 'passwd': '1234', 'db': 'first_bot' }, 'Telegram': { 'API_TOKEN': 'API_Bot' } }) try: with open(config_file, 'w', encoding='utf-8') as f: config.write(f) LOGGER.info(f'Конфигурация записана в {config_file}') except Exception as e: LOGGER.error( f'Возникла ошибка при Записи данных: {e} в файл {config_file}') LOGGER.debug(traceback.format_exc()) return config, config_file
def handle_read(self): data = self.recv(BUF_SIZE) if not data: return self.buffer_recv += data #LOGGER.debug('%s local recv %s', id(self), data) while True: if self.stage == STAGE_INIT: if len(self.buffer_recv) < 3: return ver = self.buffer_recv[0] nmethod = self.buffer_recv[1] method = self.buffer_recv[2] if ver != 5 or nmethod != 1 or method != 0: self.handle_close() LOGGER.error("error init data: ver=%d, nmethod=%d, method=%d", ver, nmethod, method) return self.buffer_recv = self.buffer_recv[3:] self.buffer_send += b'\x05\x00' self.stage = STAGE_HANDSHAKE continue elif self.stage == STAGE_HANDSHAKE: if len(self.buffer_recv) < 4: return ver = self.buffer_recv[0] cmd = self.buffer_recv[1] rsv = self.buffer_recv[2] atyp = self.buffer_recv[3] if ver != 5 or cmd != 1 or rsv != 0 or (atyp != 1 and atyp != 3): self.handle_close() LOGGER.error("error handshake data: ver=%d, cmd=%d, rsv=%d, atyp=%d", ver, cmd, rsv, atyp) return addr = "" port = 0 if atyp == 1: if len(self.buffer_recv) < 7: return addr = str(self.buffer_recv[4]) + '.' + str(self.buffer_recv[5]) + \ '.' + str(self.buffer_recv[6]) + '.' + str(self.buffer_recv[7]) port = self.buffer_recv[8] * 256 + self.buffer_recv[9] self.buffer_send += b'\x05\x00\x00\x01' + self.buffer_recv[4:10] elif atyp == 3: alen = self.buffer_recv[4] if len(self.buffer_recv) < 5 + alen + 2: return addr = self.buffer_recv[5:5 + alen].decode('utf-8') port = self.buffer_recv[5 + alen] * 256 + self.buffer_recv[5 + alen + 1] self.buffer_send += b'\x05\x00\x00\x03' + self.buffer_recv[4:5 + alen + 3] LOGGER.info('%s local handshake: %s:%d', id(self), addr, port) self.remote = RemoteConnection(self.server.server_addr, self.server.server_port, self.server.token) self.remote.local = self self.remote.buffer_send_raw += self.buffer_recv[3:] # include atyp + addr + port self.buffer_recv = b'' self.stage = STAGE_STREAM continue elif self.stage == STAGE_STREAM: self.remote.buffer_send_raw += self.buffer_recv self.buffer_recv = b'' return
def handle_accept(self): pair = self.accept() if pair is not None: sock, addr = pair LOGGER.info('incoming connection from %s', repr(addr)) handler = LocalConnection(sock) handler.server = self self.conn_list.append(handler)
def handle_read(self): """Handle read message.""" try: buff = self.recv(BUFFER_SIZE) self.append_recv_buffer += buff self.process_molo_tcp_pack() except Exception as e: LOGGER.info("recv error: %s", e)
def _start_callback(self, update, context): LOGGER.info('User {} started bot'.format( update.effective_user.username)) self._send_message(update, context, self._answers['start']) with session_scope(self._session) as session: if not session.query(User).filter_by( id=update.effective_user.id).count(): session.add( User(id=update.effective_user.id, name=update.effective_user.username)) self._send_task(update, context)
def __init__(self, address='localhost', port=DEFAULT_PORT, user=None, password=None, http_handler=None, timeout=None): if isinstance(timeout, (integer_types, float)): self._query_timeout = float(timeout) else: self._query_timeout = DEFAULT_TIMEOUT urlo = urlparse(address) if urlo.scheme == '': base_url = 'http://' + address + ':' + str(port) self.url = base_url + '/transmission/rpc' else: if urlo.port: self.url = urlo.scheme + '://' + urlo.hostname + ':' + str( urlo.port) + urlo.path else: self.url = urlo.scheme + '://' + urlo.hostname + urlo.path LOGGER.info('Using custom URL "' + self.url + '".') if urlo.username and urlo.password: user = urlo.username password = urlo.password elif urlo.username or urlo.password: LOGGER.warning( 'Either user or password missing, not using authentication.' ) if http_handler is None: self.http_handler = DefaultHTTPHandler() else: if hasattr(http_handler, 'set_authentication') and hasattr( http_handler, 'request'): self.http_handler = http_handler else: raise ValueError('Invalid HTTP handler.') if user and password: self.http_handler.set_authentication(self.url, user, password) elif user or password: LOGGER.warning( 'Either user or password missing, not using authentication.') self._sequence = 0 self.session = None self.session_id = 0 self.server_version = None self.protocol_version = None self.get_session() self.torrent_get_arguments = get_arguments('torrent-get', self.rpc_version)
def run(self): LOGGER.info('Starting bot') if MODE == 'dev': self._updater.start_polling() else: port = int(os.environ.get('PORT', '8443')) heroku_app_name = os.environ.get('HEROKU_APP_NAME', 'scatbot') self._updater.start_webhook(listen='0.0.0.0', port=port, url_path=self._token) self._updater.bot.set_webhook('https://{}.herokuapp.com/{}'.format( heroku_app_name, self._token)) self._updater.idle()
def _db_url(self): if MODE == 'prod': return os.environ['DATABASE_URL'] proc = subprocess.run('heroku config:get DATABASE_URL -a scatbot', capture_output=True, shell=True, text=True) if proc.returncode != 0 or proc.stdout is None: LOGGER.error('Failed to retrieve Heroku database URL. Aborting') sys.exit(1) else: LOGGER.info('Successfully retrieved Heroku database URL') return proc.stdout.strip()
def load_settings(): try: config, config_file = load_config(EXE_PATH) dict_setting['host'] = config.get('DB', 'host') dict_setting['user'] = config.get('DB', 'user') dict_setting['passwd'] = config.get('DB', 'passwd') dict_setting['db'] = config.get('DB', 'db') if config.get('Telegram', 'API_TOKEN') == 'API_Bot': LOGGER.info(f'Замените данные в файле {config_file} на реальные!') return False else: dict_setting['api_token'] = config.get('Telegram', 'API_TOKEN') except Exception as e: LOGGER.error(f'Возникла ошибка при Загрузки данных: {e}') LOGGER.debug(traceback.format_exc()) return dict_setting
def run() -> None: """ Starting point of ETL Here we execute ETL steps one-by-one :return: """ LOGGER.info('starting etl') LOGGER.info('step 1. specific script #1') first_etl_pipeline() LOGGER.info('step 2. specific script #2') second_etl_pipeline() LOGGER.info('etl completed')
def classify_cv_results(X, y, model, params, test_name, debug, cv=5): """ Used to get cross-validated results. :param X: features :param y: gold label :param model: model to fit :param params: parameters for GridSearchCV :param test_name: name of the test :param debug: print debug info to logger :param cv: cross validation number :return: classifier_name, accuracy, precision, recall, f1 """ gcv = GridSearchCV(model, params, cv=cv, scoring=scoring, refit='accuracy', iid=False) gcv.fit(X, y) best_model = gcv.best_estimator_ classifier_name = best_model.__class__.__name__ accuracy = np.mean(gcv.cv_results_['mean_test_accuracy']) precision = np.mean(gcv.cv_results_['mean_test_precision']) recall = np.mean(gcv.cv_results_['mean_test_recall']) f1 = np.mean(gcv.cv_results_['mean_test_f1']) if debug: LOGGER.info("************* {}: {} *************".format( classifier_name, test_name)) LOGGER.info("With best params: {}".format(gcv.best_params_)) LOGGER.info("accuracy: {}, precision: {}, recall: {}, f1: {}".format( accuracy, precision, recall, f1)) if hasattr(best_model, 'feature_importances_'): important_features = [ (X.columns[i], importance) for i, importance in enumerate(best_model.feature_importances_) if importance > 0 ] LOGGER.info('Important features: ') important_features.sort(key=operator.itemgetter(1), reverse=True) # sort by importance [ LOGGER.info('Feature {}: {}'.format(*feat)) for feat in important_features ] return classifier_name, accuracy, precision, recall, f1
def accept(self, _wsid, images, train=False): # Save the second image of the incoming array which has the movement update. path = f'{IMAGE_PATH}/{self._id}.png' images[1].save(path) LOGGER.info(f'Incoming frame saved on {path} for later reference') self._wsid = _wsid dataset = ChessBoardDataset(images, transform=self.transform) dataloader = DataLoader(dataset, batch_size=BATCH_SIZE, num_workers=NUM_WORKER, pin_memory=IS_CUDA) if train: self.result = self.train(dataloader) else: self.result = self.evaluate(dataloader)
def ping_server(self): """Send ping to server every ping_interval.""" while not self.is_exited: try: if self.molo_client: self.set_ping_buffer(self.molo_client.ping_server_buffer()) time.sleep(self.ping_interval) time_interval = time.time() - self.last_activate_time LOGGER.debug("data interval: %f", time_interval) if time_interval > PROXY_TCP_CONNECTION_ACTIVATE_TIME: LOGGER.info("connection timeout, reconnecting server") self.molo_client.handle_close() self.reset_activate_time() except Exception as exc: print("ping_server(): " + str(exc)) asyncore.close_all() self.molo_client.sock_connect() time.sleep(RECONNECT_INTERVAL) LOGGER.info("moloserver reconnecting...")
def run_commands_on_ec2_instance(ec2_connection, is_gpu): """ This function assumes that the required 'serve' folder is already available on the ec2 instance in the home directory. Returns a map of the command executed and return value of that command. """ command_result_map = {} virtual_env_name = "venv" with ec2_connection.cd(f"/home/ubuntu/serve"): ec2_connection.run(f"python3 -m venv {virtual_env_name}") with ec2_connection.prefix(f"source {virtual_env_name}/bin/activate"): commands_list = GPU_INSTANCE_COMMANDS_LIST if is_gpu else CPU_INSTANCE_COMMANDS_LIST for command in commands_list: LOGGER.info( f"*** Executing command on ec2 instance: {command}") ret_obj = ec2_connection.run( command, echo=True, warn=True, shell="/bin/bash", env={ "LC_CTYPE": "en_US.utf8", "JAVA_HOME": "/usr/lib/jvm/java-11-openjdk-amd64", "PYTHONIOENCODING": "utf8", }, encoding="utf8") if ret_obj.return_code != 0: LOGGER.error(f"*** Failed command: {command}") LOGGER.error( f"*** Failed command stdout: {ret_obj.stdout}") LOGGER.error( f"*** Failed command stderr: {ret_obj.stderr}") command_result_map[command] = ret_obj.return_code return command_result_map
def proxy_loop(self): """Handle main loop and reconnection.""" self.molo_client.sock_connect() while not self.is_exited: try: asyncore.loop(map=self.async_map) except asyncore.ExitNow as exc: logging.exception(exc) LOGGER.error("asyncore.loop exception") if not self.is_exited: try: asyncore.close_all() self.molo_client.sock_connect() time.sleep(RECONNECT_INTERVAL) LOGGER.info("moloserver reconnecting...") except Exception as exc: print("proxy_loop(): " + str(exc)) LOGGER.info("reconnect failed, retry...") time.sleep(RECONNECT_INTERVAL) asyncore.close_all() LOGGER.debug("proxy exited")
def _send_task(self, update, context): """ Get a random unfinished task and assign it to the current user. """ with session_scope(self._session) as session: task = session.query(Task).filter(Task.lemma.is_(None)).order_by( func.random()).first() if task is None: self._send_message(update, context, self._answers['all_tasks_complete']) return word = session.query(Word).filter_by(task_id=task.id).order_by( func.random()).first() session.query(User).filter_by( id=update.effective_user.id).one().current_task = task.id self._send_message( update, context, '{} ({})'.format(word.string, ', '.join(word.morph)), word.options) LOGGER.info('User {} received task {}'.format( update.effective_user.username, word.string))
def test_(frame): cv2.namedWindow('FirstFrame', flags=cv2.WINDOW_AUTOSIZE) cv2.namedWindow('SecondFrame', flags=cv2.WINDOW_AUTOSIZE) frame1 = frame[0].view(512, -1) * 255 frame2 = frame[1].view(512, -1) * 255 frame1 = frame1.numpy().astype(np.uint8) frame2 = frame2.numpy().astype(np.uint8) LOGGER.info( f'Incoming frame demonstration on UI -> FRAME1 - {frame1.shape}, FRAME2 - {frame2.shape}' ) while True: cv2.imshow('FirstFrame', frame1) cv2.imshow('SecondFrame', frame2) if cv2.waitKey(0) & 0xff == 27: break cv2.destroyAllWindows()
def __init__(self, addr, data, ss): asyncore.dispatcher.__init__(self) self.client_addr = addr atyp = data[0] if atyp == 1: self.target_addr = '.'.join( [str(data[1]), str(data[2]), str(data[3]), str(data[4])]) self.target_port = data[5] * 256 + data[6] self.send_data = data[7:] self.header = data[:7] # TODO: atyp == 3,4 else: LOGGER.info("%s udp remote target addr: error!!! %d", id(self), atyp) return LOGGER.info("%s udp remote target addr: %s:%d", id(self), self.target_addr, self.target_port) self.ss = ss self.create_socket(socket.AF_INET, socket.SOCK_DGRAM)
def update_state(self, data): """Update UI state.""" last_stage = self.cur_data.get('stage') last_notify_str = self.get_notify_str() # Update data self.cur_data.update(data) cur_stage = self.cur_data.get('stage') LOGGER.debug("cur_data %s", str(self.cur_data)) # Generate notify string according to stage if cur_stage in self.generate_str_func_bind_map: self.generate_str_func_bind_map[cur_stage]() # If notify string changed, inform UI to update if last_notify_str == self.get_notify_str(): return # If stage changed, log new stage if cur_stage != last_stage: LOGGER.info(self.state_log_str[cur_stage]) # Inform UI to update fire_molohub_event(self.molo_server_host_str, data)
def classify_cv_results(X, y, model, params, debug, cv=5): gcv = GridSearchCV(model, params, cv=cv, scoring=scoring, refit='accuracy', iid=False) gcv.fit(X, y) best_model = gcv.best_estimator_ classifier_name = best_model.__class__.__name__ accuracy = np.mean(gcv.cv_results_['mean_test_accuracy']) precision = np.mean(gcv.cv_results_['mean_test_precision']) recall = np.mean(gcv.cv_results_['mean_test_recall']) f1 = np.mean(gcv.cv_results_['mean_test_f1']) if debug: LOGGER.info("************* {} *************".format(classifier_name)) LOGGER.info("With best params: {}".format(gcv.best_params_)) LOGGER.info("accuracy: {}, precision: {}, recall: {}, f1: {}".format(accuracy, precision, recall, f1)) if hasattr(best_model, 'feature_importances_'): important_features = [(X.columns[i], importance) for i, importance in enumerate(best_model.feature_importances_) if importance > 0] LOGGER.info('Important features: ') important_features.sort(key=operator.itemgetter(1), reverse=True) # sort by importance [LOGGER.info('Feature {}: {}'.format(*feat)) for feat in important_features] return classifier_name, accuracy, precision, recall, f1
from src.do_on_fail import do_on_fail def run() -> None: """ Starting point of ETL Here we execute ETL steps one-by-one :return: """ LOGGER.info('starting etl') LOGGER.info('step 1. specific script #1') first_etl_pipeline() LOGGER.info('step 2. specific script #2') second_etl_pipeline() LOGGER.info('etl completed') if __name__ == '__main__': try: run() except Exception as etl_exception: # if any exception occurred during ETL - write error to file # or send notification if possible (for that create special function in /utils) with open(f"{ENV}_error_{datetime.now():%Y%m%d-%H%M}.log", "w") as f: f.write(str(etl_exception)) f.write(traceback.format_exc()) LOGGER.info("doing something on ETL fail") do_on_fail() LOGGER.error("etl completed with errors") raise etl_exception
warnings.filterwarnings(action='ignore', category=UserWarning, module='gensim') if __name__ == '__main__': removed_ids = [] df_res = pd.read_csv(os.path.join(DATA_DIR, 'features_all.csv')) df_res = remove_females(df_res, removed_ids) df_res = remove_depressed(df_res, removed_ids) y = df_res['label'].replace({'control': 0, 'patient': 1}) text_features = pos_tags_features + word_related_features + tf_idf_features all_features = text_features + sentiment_features + cos_sim_features data = get_features(df_res, all_features) data = add_tfidf_features(data, removed_ids) tests = [(pos_tags_features, 'PosTags'), (cos_sim_features, 'CosSim'), (sentiment_features, 'Sentiment'), (word_related_features, 'WordRelated'), (tf_idf_features, 'TfIdf'), (cos_sim_features + pos_tags_features + sentiment_features, 'CosSim + PosTags + Sentiment'), (cos_sim_features + tf_idf_features, 'CosSim + TfIdf'), (text_features, 'Text Features'), (all_features, 'All Features')] LOGGER.info( '-----------------------------------------------------------------') LOGGER.info( '------- Performing T-TestsBase of Best Classifier Results -------') LOGGER.info( '-----------------------------------------------------------------') classify_base_best_classifier(data, y, tests)
def _request(self, method, arguments=None, ids=None, require_ids=False, timeout=None): """ Send json-rpc request to Transmission using http POST """ if not isinstance(method, string_types): raise ValueError('request takes method as string') if arguments is None: arguments = {} if not isinstance(arguments, dict): raise ValueError('request takes arguments as dict') ids = parse_torrent_ids(ids) if len(ids) > 0: arguments['ids'] = ids elif require_ids: raise ValueError('request require ids') query = json.dumps({'tag': self._sequence, 'method': method , 'arguments': arguments}) self._sequence += 1 start = time.time() http_data = self._http_query(query, timeout) elapsed = time.time() - start LOGGER.info('http request took %.3f s' % (elapsed)) try: data = json.loads(http_data) except ValueError as error: LOGGER.error('Error: ' + str(error)) LOGGER.error('Request: \"%s\"' % (query)) LOGGER.error('HTTP data: \"%s\"' % (http_data)) raise LOGGER.debug(json.dumps(data, indent=2)) if 'result' in data: if data['result'] != 'success': raise TransmissionError('Query failed with result \"%s\".' % (data['result'])) else: raise TransmissionError('Query failed without result.') results = {} if method == 'torrent-get': for item in data['arguments']['torrents']: results[item['id']] = Torrent(self, item) if self.protocol_version == 2 and 'peers' not in item: self.protocol_version = 1 elif method == 'torrent-add': item = None if 'torrent-added' in data['arguments']: item = data['arguments']['torrent-added'] elif 'torrent-duplicate' in data['arguments']: item = data['arguments']['torrent-duplicate'] if item: results[item['id']] = Torrent(self, item) else: raise TransmissionError('Invalid torrent-add response.') elif method == 'session-get': self._update_session(data['arguments']) elif method == 'session-stats': # older versions of T has the return data in "session-stats" if 'session-stats' in data['arguments']: self._update_session(data['arguments']['session-stats']) else: self._update_session(data['arguments']) elif method in ('port-test', 'blocklist-update', 'free-space', 'torrent-rename-path'): results = data['arguments'] else: return None return results
def handle_read(self): data, addr = self.socket.recvfrom(UDP_SIZE) LOGGER.info('udp local recv(%s): %s', repr(addr), data) remote = RemoteSession(addr, data, self.socket) remote.local = self self.sess_list.append(remote)
async def main(): await bot.start() Config.BOT_USERNAME = (await bot.get_me()).username LOGGER.info(f"{Config.BOT_USERNAME} Started.") if Config.DATABASE_URI: try: if await db.is_saved("RESTART"): msg = await db.get_config("RESTART") if msg: try: k = await bot.edit_message_text( msg['chat_id'], msg['msg_id'], text="Succesfully restarted.") await db.del_config("RESTART") except: pass await check_changes() await sync_from_db() except Exception as e: LOGGER.error( f"Errors occured while setting up database for VCPlayerBot, check the value of DATABASE_URI. Full error - {str(e)}", exc_info=True) Config.STARTUP_ERROR = "Errors occured while setting up database for VCPlayerBot, check the value of DATABASE_URI. Full error - {str(e)}" LOGGER.info( "Activating debug mode, you can reconfigure your bot with /env command." ) await bot.stop() from utils import debug await debug.start() await idle() return if Config.DEBUG: LOGGER.info("Debugging enabled by user, Now in debug mode.") Config.STARTUP_ERROR = "Debugging enabled by user, Now in debug mode." from utils import debug await bot.stop() await debug.start() await idle() return try: await group_call.start() Config.USER_ID = (await USER.get_me()).id k = await startup_check() if k == False: LOGGER.error("Startup checks not passed , bot is quiting") await bot.stop() LOGGER.info( "Activating debug mode, you can reconfigure your bot with /env command." ) from utils import debug await debug.start() await idle() return if Config.IS_LOOP: if Config.playlist: await play() LOGGER.info( "Loop play enabled and playlist is not empty, resuming playlist." ) else: LOGGER.info( "Loop play enabled , starting playing startup stream.") await start_stream() except Exception as e: LOGGER.error(f"Startup was unsuccesfull, Errors - {e}", exc_info=True) LOGGER.info( "Activating debug mode, you can reconfigure your bot with /env command." ) Config.STARTUP_ERROR = f"Startup was unsuccesfull, Errors - {e}" from utils import debug await bot.stop() await debug.start() await idle() return await idle() await bot.stop()
data = get_features(df_res, all_features) data = add_tfidf_features(data, removed_ids) tests = [ (pos_tags_features, 'PosTags'), (cos_sim_features, 'CosSim'), (sentiment_features, 'Sentiment'), (word_related_features, 'WordRelated'), (tf_idf_features, 'TfIdf'), (cos_sim_features + pos_tags_features + sentiment_features, 'CosSim + PosTags + Sentiment'), (cos_sim_features + tf_idf_features, 'CosSim + TfIdf'), (text_features, 'Text Features'), (all_features, 'All Features') ] LOGGER.info('-----------------------------------------------------------------') LOGGER.info('--------------------- Performing Base Tests ---------------------') LOGGER.info('-----------------------------------------------------------------') classify_base(data, y, tests, options.debug) LOGGER.info('-----------------------------------------------------------------') LOGGER.info('----------------- Performing Per-Question Tests -----------------') LOGGER.info('-----------------------------------------------------------------') classify_per_question(data, y, tests, options.debug) LOGGER.info('-----------------------------------------------------------------') LOGGER.info('----------------- Performing Question Type Tests ----------------') LOGGER.info('-----------------------------------------------------------------') classify_question_types(data, y, tests, options.debug)
def do_on_fail() -> None: """ Do on failure script :return: """ LOGGER.info('start do-on-fail')