Esempio n. 1
0
    def send_menu(context):
        # get menu today
        menu = get_raw_menu(meal, localized_date_today())

        if menu is None:
            return

        # get the subscribers before the broadcast
        subscribers = get_broadcast_subscribers(meal)

        logging.info(
            f"meal broadcast in progress... number of subscribers: {len(subscribers)}"
        )

        for user_id in subscribers:
            chat_id = user_id[
                0]  # extracts chat_id from nested [] from database
            hidden_cuisines = get_hidden_cuisines(chat_id)
            context.bot.send_message(chat_id=chat_id,
                                     text=menu_msg(
                                         localized_date_today(), meal,
                                         parse_menu(menu, hidden_cuisines)),
                                     parse_mode='HTML')
            logging.info(f"{chat_id}: {meal} menu broadcast")

        logging.info("meal broadcast finished")
Esempio n. 2
0
    def send_menu(context):
        date = localized_date_tomorrow() if tomorrow else localized_date_today
        menu = get_raw_menu(meal, date)

        if menu is None:
            return

        # get the subscribers before the broadcast
        subscribers = get_broadcast_subscribers(meal)

        logging.info(
            f"meal broadcast in progress... number of subscribers: {len(subscribers)}"
        )

        for user_id in subscribers:
            # extracts chat_id from nested [] from database
            chat_id = user_id[0]
            hidden_cuisines = get_hidden_cuisines(chat_id)
            reply_markup = breakfast_opt_kb if meal is BREAKFAST else dinner_opt_kb
            try:
                context.bot.send_message(
                    chat_id=chat_id,
                    text=menu_msg_opt_in(date, meal, parse_menu(menu, hidden_cuisines)),
                    reply_markup=reply_markup(hidden_cuisines, date),
                    parse_mode=telegram.ParseMode.HTML,
                )
            except Exception:
                logging.warning(
                    f"{chat_id}: exception occurs, reverting user's subscription status"
                )
                update_subscribe_setting(chat_id, meal)
                continue
            logging.info(f"{chat_id}: {meal} menu broadcast")

        logging.info("meal broadcast finished")
Esempio n. 3
0
    def get_breakfast_or_dinner_menu(update, context):
        if update.callback_query is not None:
            context.bot.answer_callback_query(update.callback_query.id)
        chat_id = update.effective_chat.id
        # send the user menu
        entered_date = ''
        if update.callback_query is None:
            entered_date = ' '.join(context.args)
        parsed_date = get_menu_query_date(entered_date)

        if parsed_date is None:
            context.bot.send_message(chat_id=chat_id,
                                     text=failed_to_parse_date_msg(entered_date))
            return

        menu = get_raw_menu(meal, parsed_date)
        hidden_cuisines = get_hidden_cuisines(update.effective_chat.id)

        if menu is None:  # if no menu, reply with no menu message
            context.bot.send_message(chat_id=chat_id,
                                     text=no_menu_msg(meal),
                                     reply_markup=start_button_kb())
        else:  # else reply user of the menu
            menu = menu_msg(parsed_date, meal, parse_menu(menu, hidden_cuisines))
            # send formatted menu to client
            context.bot.send_message(chat_id=chat_id,
                                     text=menu,
                                     parse_mode=telegram.ParseMode.HTML,
                                     reply_markup=start_button_kb())
        logging.info(f"{chat_id}: {meal} menu sent to chat")
Esempio n. 4
0
    def send_menu(context):
        # get menu today
        menu = get_raw_menu(meal, localized_date_today())

        if menu is None:
            return

        # get the subscribers before the broadcast
        subscribers = get_broadcast_subscribers(meal)

        logging.info(
            f"meal broadcast in progress... number of subscribers: {len(subscribers)}"
        )

        for user_id in subscribers:
            chat_id = user_id[
                0]  # extracts chat_id from nested [] from database
            hidden_cuisines = get_hidden_cuisines(chat_id)
            try:
                context.bot.send_message(chat_id=chat_id,
                                         text=menu_msg(
                                             localized_date_today(), meal,
                                             parse_menu(menu,
                                                        hidden_cuisines)),
                                         reply_markup=start_button_kb(),
                                         parse_mode='HTML')
            except Exception:
                logging.warning(
                    f"{chat_id}: exception occurs, reverting user's subscription status"
                )
                update_subscribe_setting(chat_id, meal)
                continue
            logging.info(f"{chat_id}: {meal} menu broadcast")

        logging.info("meal broadcast finished")
Esempio n. 5
0
def handle_hidden_cuisine(update, context):
    if update.callback_query is not None:
        context.bot.answer_callback_query(update.callback_query.id)
    hidden_cuisine = get_hidden_cuisines(update.effective_chat.id)
    msg = no_hidden_cuisine_msg(
    ) if not hidden_cuisine else hidden_cuisine_msg(
        update.effective_chat.first_name)

    context.bot.send_message(chat_id=update.effective_chat.id,
                             text=msg,
                             reply_markup=hidden_cuisine_kb(hidden_cuisine),
                             parse_mode=telegram.ParseMode.HTML)