Пример #1
0
async def selectCity(message: types.Message, state: FSMContext):
    await message.delete()
    if message.text.split('.')[0].isdigit():
        currentState = await getCurrentState(state)
        elemNumber = int(message.text.split('.')[0]) - 1
        weatherSearch = await state.get_data('search')
        await message.answer(await
                             getWeather(weatherSearch['search'][elemNumber],
                                        state),
                             reply_markup=futureWeatherInlineMarkup(),
                             disable_notification=True)
        if currentState in ['setMainCity', 'selectMainCity']:
            user = User(message.from_user.id)
            user.setMainCity(weatherSearch['search'][elemNumber][1])
            if currentState == 'selectMainCity':
                await deleteMessages(message.message_id, message.chat.id,
                                     state)
                await message.answer(
                    f"{weatherSearch['search'][elemNumber][0]} установлен как город по умолчанию\n"
                    f"Настройка закончена, спасибо 🤗",
                    reply_markup=mainMarkup())
                await sendKeanu(message.chat.id)
                await state.reset_state()
                return
            else:
                await message.answer(
                    f"{weatherSearch['search'][elemNumber][0]} установлен как город по умолчанию",
                    reply_markup=settingsMarkup(user))
                await SettingsState.settingsMenu.set()
    elif message.text == 'Искать еще 🔍':

        await message.answer('Укажите населенный пункт 🏙️',
                             reply_markup=locationMarkup(),
                             disable_notification=True)
        await WeatherState.weatherMenu.set()
Пример #2
0
async def weatherBySearch(message: types.Message, state: FSMContext):
    weatherSearch = searchCities(message.text)
    currentState = await getCurrentState(state)
    if weatherSearch.__len__() == 0:
        await message.answer(
            'К сожалению, населенного пункта с таким названием не найдено 😥')
        if currentState == 'indicateMainCity':
            return
    elif weatherSearch.__len__() == 1:
        if currentState == 'indicateMainCity':
            await message.answer(await getWeather(weatherSearch[0]))
            user = User(message.from_user.id)
            user.setMainCity(weatherSearch[0])
            await deleteMessages(message.message_id, message.chat.id, state)
            await message.answer(
                f"{weatherSearch[0][0]} установлен как город по умолчанию\n"
                f"Настройка закончена, спасибо 🤗",
                reply_markup=mainMarkup())
            await sendKeanu(message.chat.id)
            await state.reset_state()
            return

        await message.answer(await getWeather(weatherSearch[0], state),
                             reply_markup=futureWeatherInlineMarkup())
        return
    else:
        await message.answer('Укажите населенный пункт 🏙️',
                             reply_markup=weatherMarkup(
                                 cityList=weatherSearch,
                                 addSearch=currentState == 'weatherMenu'),
                             disable_notification=True)
    await state.update_data({'search': weatherSearch})
    if currentState == 'searchMainCity':
        await SettingsState.setMainCity.set()
    elif currentState == 'indicateMainCity':
        await FirstSettings.selectMainCity.set()
    else:
        await WeatherState.searchState.set()
Пример #3
0
async def weatherByLocation(message: types.Message, state: FSMContext):
    await message.delete()
    cityList = getLocation(message.location)
    currentState = await getCurrentState(state)
    if cityList.__len__() == 1:
        if currentState in [
                'setMainCity', 'indicateMainCity', 'searchMainCity'
        ]:
            await message.answer(await getWeather(cityList[0]))
            user = User(message.from_user.id)
            user.setMainCity(cityList[0][1])
            if currentState in ['setMainCity', 'searchMainCity']:
                await message.answer(
                    f"{cityList[0][0]} установлен как город по умолчанию",
                    reply_markup=settingsMarkup(user))
                await SettingsState.settingsMenu.set()
            else:
                await deleteMessages(message.message_id, message.chat.id,
                                     state)
                await message.answer(
                    f"{cityList[0][0]} установлен как город по умолчанию\n"
                    f"Настройка закончена, спасибо 🤗",
                    reply_markup=mainMarkup())
                await sendKeanu(message.chat.id)
                await state.reset_state()
        else:
            await message.answer(await getWeather(cityList[0]),
                                 reply_markup=futureWeatherInlineMarkup())
    elif cityList.__len__() > 1:
        await message.answer(
            'К сожалению, не удалось точно определить населенный пункт. Но вот, что я нашел 🙄',
            reply_markup=weatherMarkup(cityList, addSearch=False))
        await state.set_state(cityList)
        if currentState == 'searchState':
            await WeatherState.searchState.set()
    else:
        await message.answer('Вообще ничего не нашел 🥺')