class location(StatesGroup):
get = State()
selects = State()
@dp.message_handler(commands = ['locate_me'])
async def cmd_locate_me(message: types.Message):
reply = "Нажмите здесь, чтобы поделиться геопозицией"
await message.answer(reply, reply_markup = get_location_keyboard())
await location.get.set()
@dp.message_handler(content_types = ['location'], state=location.get)
async def handle_location(message: types.Message, state: FSMContext):
lat = round(message.location.latitude, 3)
lon = round(message.location.longitude, 3)
location = []
location.append(lat), location.append(lon)
reply = "Широта: {}\nДолгота: {}".format(lat, lon)
await message.answer(reply, reply_markup = types.ReplyKeyboardRemove())
await bot.send_message(message.from_user.id,
'Теперь мы видим, где ты находишься) \n'
'Выбери действие и узнаешь погоду в своем городе ',
reply_markup = get_weather_keyboard())
async with state.proxy() as data:
data['location'] = location
await location.selects.set()
@dp.message_handler(content_types = ['text'], state=location.selects)
async def weather(message: types.Message, state: FSMContext):
async with state.proxy() as data:
handle_location = data['location']
if message.text == 'Погода сейчас':
reply_current = current_weather(handle_location)
await message.answer(message.from_user.id, reply_current)
if message.text == 'Погода на сегодня':
reply_today = today_weather(handle_location)
await message.answer(message.from_user.id, reply_today)
if message.text == 'Погода на завтра':
reply_tomorrow = tomorrow_weather(handle_location)
await message.answer(message.from_user.id, reply_tomorrow)
if message.text == 'Погода на 4 дня':
reply_week = week_weather(handle_location)
await message.answer(message.from_user.id, reply_week)