Beispiel #1
0
def bot_runner(thread_statuses, q_offer, bot_settings_file, bot_configs_dir):
    """ Function creates a Telegram Bot and supplies it with offers from q_offer queue.
    :param thread_statuses: used for debugging and checking up on threads
    :param q_offer: offers which are supplied to the bot
    :param bot_settings_file: settings file path
    :param bot_configs_dir: configs directory path
    """
    # Starting the bot
    thread_statuses[current_thread().name] = "Booting"
    try:
        bot = TelegramBot(bot_settings_file, bot_configs_dir)
    except Exception as err:
        thread_statuses[current_thread().name] = "Error -- %s" % err.__str__()
        return
    bot.start()

    while not current_thread().is_stopped():
        thread_statuses[current_thread().name] = "Waiting"

        while q_offer.qsize() > 0:
            # Get an offer and update status
            thread_statuses[current_thread().name] = "Work %02d" % q_offer.qsize()
            offer = q_offer.get()

            # Process the offer (and send it if that's needed
            bot.process_offer(offer)

    bot.stop()
    thread_statuses[current_thread().name] = "Stopped"
Beispiel #2
0
        scanner = RouterOsScanner(INTERVAL, SCANNER['address'],
                                  SCANNER["username"], SCANNER["password"],
                                  ssl_context, subnet_filters)
    else:
        raise ValueError(
            "Unknown scanner type. Should be one of ['arping', 'routeros_api']"
        )

    scanner.set_new_device_alert(new_device_alert)

    bot = TelegramBot(TOKEN, BotMainState)
    bot.allow_chat(ADMIN_CHAT)

    print("Starting bot...")
    bot.start()
    print("Bot started")

    print("Starting scanner...")
    scanner.start()
    print("Scanner started")

    try:
        while True:
            sleep(300)
    except KeyboardInterrupt as e:
        print("Interrupted")
        print("Stop bot")
        bot.stop()
        print("Stop scanner")
        scanner.stop()
Beispiel #3
0
handler.setFormatter(logFormatter)
logger = logging.getLogger('Logger')
logger.setLevel(logging.INFO)
logger.addHandler(handler)
logger.info('Start main')

logger.info('Load config')
config = configparser.ConfigParser()
config.read('motion-sensor.ini')

pool = multiprocessing.Pool(processes=3)
m = multiprocessing.Manager()
camQueue = m.Queue()
botQueue = m.Queue()

logger.info('Init cam')
cam = CamThread(3, "Camera", config, logger, camQueue, botQueue)
cam.start()

logger.info('Init motion sensor')
pirThread = PirThread(1, "PirThread", config, logger)
pirThread.start()

logger.info('Init bot')
telegramBot = TelegramBot(1, "Bot", config, logger, pirThread, cam, botQueue)
telegramBot.start()
cam.addBot(telegramBot)
pirThread.addBot(telegramBot)

logger.info('Init complete')