Esempio n. 1
0
async def exit_locations(call: CallbackQuery, callback_data: dict,
                         state: FSMContext):
    await call.answer(cache_time=1)
    data = await state.get_data()
    await state.update_data(lastLocations=callback_data.get('name_place'))
    closes_places = choose_nearest(
        data.get("locations_from_user")[0],
        data.get("locations_from_user")[-1], Attractions,
        callback_data.get('name_place'))
    if not closes_places:
        await RemoveButtonsInInlineKeyboard(
            closes_places, call, callback_data,
            callback_data.get('number_to_remove'))
        return
    await SendToUserLocationUpdateDataBase(closes_places, call)
Esempio n. 2
0
async def exit_locations(call: CallbackQuery, callback_data: dict,
                         state: FSMContext):
    data = await state.get_data()
    await call.answer(cache_time=1)
    # заносим в Машину состояний имя того объекта, на который он нажал
    await state.update_data(lastLocations=callback_data.get('name_place'))
    # получаем нужную информацию об объекте(имя,ссылка,координаты)
    closes_places = choose_nearest(
        data.get("locations_from_user")[0],
        data.get("locations_from_user")[-1], Attractions,
        callback_data.get('name_place'))
    if not closes_places:
        await RemoveButtonsInInlineKeyboard(
            closes_places, call, callback_data,
            callback_data.get('number_to_remove'))
        return
    await SendToUserLocationUpdateDataBase(closes_places, call)
Esempio n. 3
0
async def go_to_nex_location(message: types.Message):
    new_lat, new_lon = db.get_coordinates(id=message.from_user.id)
    closes_places = choose_nearest(message, new_lat, new_lon, New_Attract)
    if not closes_places:
        await message.answer(text=
                             "Список мест для посещения закончилось!"
                             "Для завершения нажмите /finish")
        return

    text_format = "{place_name}.\n" \
                  "Маршрут: <a href='{url}'>Google</a>\n" \
                  "Расстояние до объекта: {distance:.2f} км"
    text = "\n\n".join(
        [
            text_format.format(place_name=place_name, url=url, distance=distance)
            for place_name, distance, url, place_location in closes_places
        ]
    )
    # получаем имя локации, к которой нас отправили
    # name_of_location = re.match('^[^.]*', text).group(0)
    # получаем тьюпл локации
    # tuple_location, iteration = find_locale(name_of_location)
    '''
    await message.answer(f"Имя локации = {name_of_location}\n"
                         f"\nlon = {tuple_location.get('lon')}"
                         f"\nlat = {tuple_location.get('lat')}") 
    '''

    await message.answer(f'Спасибо за отправку!\n'
                         f'Ближайшая к вам:\n'
                         f'{text}',
                         disable_web_page_preview=True, reply_markup=ReplyKeyboardRemove()
                         # Добавил reply_markup=ReplyKeyboardRemove(),
                         # т.е. убираем клаву после отправки геопозиции
                         )
    for place_name, distance, url, place_location in closes_places:
        await message.answer_location(
            latitude=place_location["lat"],
            longitude=place_location["lon"]
        )
        # Обновляем данные в БД
        db.update_lat(id=message.from_user.id, lat=place_location["lat"])
        db.update_lon(id=message.from_user.id, lon=place_location["lon"])
    await message.answer("Чтобы перейти к следующией ближайшей достопримечательности нажмите /next")
    await message.answer("Для завершения нажмите /finish")
Esempio n. 4
0
async def exit_locations(call: CallbackQuery, callback_data: dict,
                         state: FSMContext):
    await call.answer(cache_time=1)
    data = await state.get_data()
    await state.update_data(lastLocations=callback_data.get('name_place'))
    # await call.message.answer(text=f"{callback_data.get('type_place')} {callback_data.get('name_place')}")
    # await call.message.answer(
    #     text=str(data.get("locations_from_user")[0]) + " " + str(data.get("locations_from_user")[-1]))
    closes_places = choose_nearest(
        data.get("locations_from_user")[0],
        data.get("locations_from_user")[-1], Attractions,
        callback_data.get('name_place'))
    if not closes_places:
        await RemoveButtonsInInlineKeyboard(
            closes_places, call, callback_data,
            callback_data.get('number_to_remove'))
        return

    text_format = "{place_name}.\n" \
                  "Маршрут: <a href='{url}'>Google</a>\n" \
                  "Расстояние до объекта: {distance:.2f} км\n"
    text = "\n\n".join([
        text_format.format(place_name=place_name, url=url, distance=distance)
        for place_name, distance, url, place_location in closes_places
    ])

    await call.message.answer(
        f'Спасибо за отправку!\n'
        f'Ближайшая к вам:\n'
        f'{text}',
        disable_web_page_preview=True)
    for place_name, distance, url, place_location in closes_places:
        # отправляем пользователю объект по его точному местоположению
        await call.message.answer_location(latitude=place_location["lat"],
                                           longitude=place_location["lon"])
        # Обновляем данные юзера в БД
        db.update_lat(id=call.from_user.id, lat=place_location["lat"])
        db.update_lon(id=call.from_user.id, lon=place_location["lon"])

    await call.message.answer(
        text="Если вы хотите продолжить, нажмите кнопку ниже\n",
        reply_markup=NextOrFinishLocationKeyboard)
Esempio n. 5
0
async def next_place(call: CallbackQuery, callback_data: dict,
                     state: FSMContext):
    await call.answer(cache_time=1)
    data = await state.get_data()
    user = db.select_user(id=call.from_user.id)
    # получаем координаты из БД
    # postgres : await db.get_coordinates(id=call.from_user.id)
    new_lat, new_lon = db.get_coordinates(id=call.from_user.id)
    closes_places = choose_nearest(new_lat,
                                   new_lon,
                                   Attractions,
                                   name_object=data.get('lastLocations'))
    if not closes_places:
        await call.message.edit_text(
            text='Список мест для посещения закончилось!\n')
        await call.message.edit_reply_markup()
        await call.message.answer(text="Чтобы сбросить карту нажмите /")
        return

    await SendToUserLocationUpdateDataBase(closes_places, call)
Esempio n. 6
0
async def get_location(message: types.Message, state: FSMContext):
    # получение координат из бд юзера
    # latt,lonn = db.get_coordinates(id=message.from_user.id)
    location = message.location
    latitude = location.latitude
    longitude = location.longitude
    closes_places = choose_nearest(message, latitude, longitude, New_Attract.copy())
    if not closes_places:
        await message.answer("Список мест для посещения пуст!", reply_markup=ReplyKeyboardRemove())
        return

    # await message.answer(f"\n\n start_position,last_position = {new_start} {new_last}\n\n")

    text_format = "{place_name}.\n" \
                  "Маршрут: <a href='{url}'>Google</a>\n" \
                  "Расстояние до объекта: {distance:.2f} км"
    text = "\n\n".join(
        [
            text_format.format(place_name=place_name, url=url, distance=distance)
            for place_name, distance, url, place_location in closes_places
        ]
    )

    await message.answer(f'Спасибо за отправку!\n'
                         f'Ближайшая к вам:\n'
                         f'{text}',
                         disable_web_page_preview=True, reply_markup=ReplyKeyboardRemove()
                         # Добавил reply_markup=ReplyKeyboardRemove(),
                         # т.е. убираем клаву после отправки геопозиции
                         )
    for place_name, distance, url, place_location in closes_places:
        await message.answer_location(
            latitude=place_location["lat"],
            longitude=place_location["lon"]
        )
        # Обновляем данные в БД
        db.update_lat(id=message.from_user.id, lat=place_location["lat"])
        db.update_lon(id=message.from_user.id, lon=place_location["lon"])
    await message.answer("Чтобы перейти к следующией ближайшей достопримечательности нажмите /next")
    await message.answer("Для завершения нажмите /finish")
Esempio n. 7
0
async def go_to_local(message: types.Message):
    location = message.location
    latitude = location.latitude
    longitude = location.longitude
    atract_nearest = choose_nearest(location)

    text_format = "Название: {attract_name}. <a href ='{url}'>Google</a>\n Расстояние равно: {distance:.1f} км"
    new_text = "\n\n".join([
        ##text_format.format(atract_name=attract_name, url=url, distance=distance)
        # for atract_name, url, distance, atract_local in atract_nearest
    ])

    await message.answer(
        f"Cпасибо за ответ\n"
        "Коордитаны:\n"
        f"Широта: {latitude}\n"
        f"Долгота:{longitude}\n\n"
        "Ближайшее к вам будет:"
        f"{new_text}",
        disable_web_page_preview=True)
    for atract_name, url, distance, atract_local in atract_nearest:
        await message.answer_location(latitude=atract_local["lat"],
                                      longitude=atract_local["lon"])