Пример #1
0
async def get_price_from_msg(message: types.Message):
    re_parser = re.search(r"(\d+)\s*-\s*(\d+)", message.text)
    try:
        min_price = float(re_parser[1].replace(',', '.'))
        max_price = float(re_parser[2].replace(',', '.'))
    except (IndexError, ValueError):
        await message.answer(messages.GET_PRICE_FROM_MSG_ALERT)
        return

    session = Session(bind=db.models.engine)
    user = session.query(db.models.User).filter(db.models.User.telegram_id == message.from_user.id).one()
    current_query = [q for q in user.queries if q.id == user.settings.editing_query][0]
    current_query.price = [min_price, max_price]

    await bot.bot_instance.send_message(
        text=messages.search_terms_answer(current_query.region,
                                          current_query.deal,
                                          current_query.underground,
                                          current_query.rooms,
                                          current_query.apartment_type,
                                          current_query.price),
        chat_id=message.from_user.id,
        parse_mode='Markdown'
    )
    await asyncio.sleep(1)
    await bot.bot_instance.send_message(
        text=messages.SEARCH_TERMS,
        chat_id=message.from_user.id,
        reply_markup=buttons.build_inlinekeyboard(buttons.SEARCH_TERMS)
    )
    db.utils.safe_commit(session)
Пример #2
0
async def callback_underground_line(query: types.CallbackQuery):
    if query.data == "Любая станция":
        session = Session(bind=db.models.engine)
        user = session.query(db.models.User).filter(db.models.User.telegram_id == query.from_user.id).one()
        current_query = [q for q in user.queries if q.id == user.settings.editing_query][0]
        current_query.underground = None
        await bot.bot_instance.send_message(
            text=messages.search_terms_answer(current_query.region,
                                              current_query.deal,
                                              current_query.underground,
                                              current_query.rooms,
                                              current_query.apartment_type,
                                              current_query.price),
            chat_id=query.from_user.id,
            parse_mode='Markdown'
        )
        await asyncio.sleep(1)
        await bot.bot_instance.send_message(
            text=messages.SEARCH_TERMS,
            chat_id=query.from_user.id,
            reply_markup=buttons.build_inlinekeyboard(buttons.SEARCH_TERMS)
        )

    else:
        metro_stations = filters.underground_voc[query.data].items()
        metro_stations = [(s, f"underground_station {id}") for s, id in metro_stations]

        await bot.bot_instance.send_message(
            text=messages.GET_UNDERGROUND2,
            chat_id=query.from_user.id,
            disable_web_page_preview=True,
            reply_markup=buttons.build_inlinekeyboard(buttons.Buttons(items=metro_stations)))

    await query.answer()
Пример #3
0
async def callback_get_underground_station(query: types.CallbackQuery):
    session = Session(bind=db.models.engine)
    user = session.query(db.models.User).filter(db.models.User.telegram_id == query.from_user.id).one()
    current_query = [q for q in user.queries if q.id == user.settings.editing_query][0]
    station = int(query.data.split(' ')[1])
    current_query.underground = station
    current_query.pages = None

    await bot.bot_instance.send_message(
        text=messages.search_terms_answer(current_query.region,
                                          current_query.deal,
                                          current_query.underground,
                                          current_query.rooms,
                                          current_query.apartment_type,
                                          current_query.price),
        chat_id=query.from_user.id,
        parse_mode='Markdown'
    )
    await asyncio.sleep(1)
    await bot.bot_instance.send_message(
        text=messages.SEARCH_TERMS,
        chat_id=query.from_user.id,
        reply_markup=buttons.build_inlinekeyboard(buttons.SEARCH_TERMS)
    )

    db.utils.safe_commit(session)
    await query.answer()
Пример #4
0
async def callback_get_rooms(query: types.CallbackQuery):
    session = Session(bind=db.models.engine)
    user = session.query(db.models.User).filter(db.models.User.telegram_id == query.from_user.id).one()
    current_query = [q for q in user.queries if q.id == user.settings.editing_query][0]
    current_query.pages = None

    if query.data != 'Готово!':
        selected_rooms_type = filters.rooms_filter(query.data, mode='to_int')

        if not current_query.rooms:
            result = {*selected_rooms_type}
        else:
            result = set(current_query.rooms)
            for room in selected_rooms_type:
                if room not in current_query.rooms:
                    result.add(room)
                else:
                    result.remove(room)
        current_query.rooms = list(result)

        db.utils.safe_commit(session)
        await query.answer("Квартиры: {}".format(filters.rooms_filter(list(result), mode='array_to_str')))

    else:
        session = Session(bind=db.models.engine)
        user = session.query(db.models.User).filter(db.models.User.telegram_id == query.from_user.id).one()
        current_query = [q for q in user.queries if q.id == user.settings.editing_query][0]

        await bot.bot_instance.send_message(
            text=messages.search_terms_answer(current_query.region,
                                              current_query.deal,
                                              current_query.underground,
                                              current_query.rooms,
                                              current_query.apartment_type,
                                              current_query.price),
            chat_id=query.from_user.id,
        parse_mode='Markdown'
        )
        await asyncio.sleep(1)
        await bot.bot_instance.send_message(
            text=messages.SEARCH_TERMS,
            chat_id=query.from_user.id,
            reply_markup=buttons.build_inlinekeyboard(buttons.SEARCH_TERMS)
        )

        session.close()
        await query.answer()