def calc(bot, update): # text = user_text.strip(' ') try: keyboard.start(bot, update) except AttributeError as e: print(e) update.message.reply_text('что-то не получилось')
def __init__(self, write_history=True, run_callbacks=True): global do_validation do_validation = False self.write_history = write_history self.run_callbacks = run_callbacks # validation def validation(): global do_validation do_validation = True return True # continue listener # Collect events until released keyboard.listen_key('v', validation) keyboard.start() print("! note: press 'v' to run validation") super(Callback, self).__init__()
async def register(message: types.Message): Users().register_user(message.from_user.id, message.from_user.username, message.from_user.first_name, message.from_user.last_name) text = "Привет, " + message.from_user.first_name + "! Меня разработал @thebordevs, видеоролик по созданию этого бота ты сможешь найти на его YouTube\nКод проекта на GitHub" await message.answer(text, reply_markup=keyboard.start()) await message.answer("<b>Что я умею?</b>" "\n\n<i>Я могу вести статистику твоего Телеграм канала, вести переговоры с рекламодателями, " "зарабатывая тем самым тебе копеечку. Добавь бота в администраторы своего сообщества, предоставь доступ к" "сообщениям и все! Предложения по рекламным контрактом буду присылать тебе лично, но такжже ты и сам можешь найти его себе на нашей " "бирже! Все очень просто!</i>", parse_mode="HTML", reply_markup=keyboard.main())
def __init__(self): global stop_training stop_training = False # stop def on_stop(): global stop_training, stop_training_now # twice press if stop_training: stop_training_now = True self.model.info( '\n -> Key \'q\' pressed twice. Training will stop at the end of step! \n\n' ) return False # stop listener # first press else: stop_training = True self.model.info( '\n -> Training will stop at the end of epoch! \n\n') return True # continue listener # stop def on_resume(): global stop_training, stop_training_now if stop_training_now: print("\n -> Sorry, can't resume train, double 'q' pressed") else: stop_training = False self.model.info('\n -> Training will resume! \n\n') return True # continue listener # Collect events until released keyboard.listen_key('q', on_stop) keyboard.listen_key('Q', on_resume) keyboard.start() print( "! note: press 'q' to stop training; 'Q' to resume; twice 'q' to stop after step" ) super(Callback, self).__init__()
def __init__(self, step_percent=0.2): # decrease def decrease_lr(): self.model.learning_rate *= 1 - step_percent self.model.info( '\n -> Keyboard: Learning rate decreased to %0.2E \n\n' % self.model.learning_rate) # increase def increase_lr(): self.model.learning_rate *= 1 + step_percent self.model.info( '\n -> Keyboard: Learning rate increased to %0.2E \n\n' % self.model.learning_rate) # Collect events until released keyboard.listen_key('-', decrease_lr) keyboard.listen_key('+', increase_lr) keyboard.listen_key('=', increase_lr) keyboard.start() print("! note: press '+/=' to increase learning rate, '-' to decrease") super(Callback, self).__init__()
headset.listener.initial = 0 elif headset.listener.timer() > 500: headset.listener.initial = 0 if __name__ == '__main__': headset = mindwave.Headset('/dev/ttyUSB0') time.sleep(2) headset.connect() print "Connecting" while headset.status != 'connected': time.sleep(0.5) if headset.status == 'standby': headset.connect() print "Retrying" try: print "connected" headset.blink_handlers.append(on_blink) headset.raw_value_handlers.append(on_raw) headset.raw_value_handlers.append(send_poor) keyboard.start() except KeyboardInterrupt: headset.disconnect() except: headset.disconnect() print "Unknown Error" raise
on_blink(headset) headset.listener.initial=0 elif headset.listener.timer()>500: headset.listener.initial=0 if __name__ == '__main__': headset = mindwave.Headset('/dev/ttyUSB0') time.sleep(2) headset.connect() print "Connecting" while headset.status != 'connected': time.sleep(0.5) if headset.status == 'standby': headset.connect() print "Retrying" try: print "connected" headset.blink_handlers.append(on_blink) headset.raw_value_handlers.append(on_raw) headset.raw_value_handlers.append(send_poor) keyboard.start() except KeyboardInterrupt: headset.disconnect() except: headset.disconnect() print "Unknown Error" raise