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"