TG_bot aiogram. Получение ответа из вложенного списка
Подскажите, пожалуйста, как в цикле получить из списка ответ только по нажатой стране и четыре инлайн кнопки. На данный момент при нажатии любой страны происходит итерация по всем странам и всем ссылкам.
from re import X
from aiogram import Bot, types
from aiogram.dispatcher import Dispatcher
from aiogram.utils import executor
from aiogram.types import InlineKeyboardMarkup, InlineKeyboardButton
import os
bot = Bot(token=os.getenv('TOKEN'))
dp = Dispatcher(bot)
@dp.message_handler(commands="start")
async def cmd_start(message: types.Message):
keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True, one_time_keyboard=True)
button_1 = "Нидерланды"
button_2 = "Франция"
button_3 = "Испания"
button_4 = "РФ"
button_5 = "Казахстан"
button_6 = "Беларусь"
keyboard.add(button_1,button_2,button_3,button_4,button_5,button_6)
await message.answer("Привет! Откуда ты?", reply_markup=keyboard)
countries = [
{
'name': 'Нидерланды',
'flag': '??',
'socials': [
{ 'text': 'Youtube', 'url': 'youtube.com' },
{ 'text': 'Yandex', 'url': 'yandex.com' },
{ 'text': 'Google', 'url': 'google.nl' },
{ 'text': 'Instagram', 'url': 'instagram.com' },
]
},
{
'name': 'Франция',
'flag': '??',
'socials': [
{ 'text': 'Youtube', 'url': 'youtube.com' },
{ 'text': 'Yandex', 'url': 'yandex.com' },
{ 'text': 'Google', 'url': 'google.fr' },
{ 'text': 'Instagram', 'url': 'instagram.com' },
]
},
{
'name': 'Испания',
'flag': '??',
'socials': [
{ 'text': 'Youtube', 'url': 'youtube.com' },
{ 'text': 'Yandex', 'url': 'yandex.com' },
{ 'text': 'Google', 'url': 'google.es' },
{ 'text': 'Instagram', 'url': 'instagram.com' },
]
},
{
'name': 'РФ',
'flag': '??',
'socials': [
{ 'text': 'Youtube', 'url': 'youtube.com' },
{ 'text': 'Yandex', 'url': 'yandex.ru' },
{ 'text': 'Google', 'url': 'google.ru' },
{ 'text': 'Instagram', 'url': 'instagram.com' },
]
},
{
'name': 'Казахстан',
'flag': '??',
'socials': [
{ 'text': 'Youtube', 'url': 'youtube.com' },
{ 'text': 'Yandex', 'url': 'yandex.kz' },
{ 'text': 'Google', 'url': 'google.kz' },
{ 'text': 'Instagram', 'url': 'instagram.com' },
]
},
{
'name': 'Беларусь',
'flag': '??',
'socials': [
{ 'text': 'Youtube', 'url': 'youtube.com' },
{ 'text': 'Yandex', 'url': 'yandex.by' },
{ 'text': 'Google', 'url': 'google.by' },
{ 'text': 'Instagram', 'url': 'instagram.com' },
]
},
]
@dp.message_handler(lambda message: '' in message.text)
async def foo(message: types.Message):
keyboard = types.InlineKeyboardMarkup()
for c in countries:
for s in c['socials']:
keyboard.add(types.InlineKeyboardButton(text = s['text'], url = s['url']))
for c in countries:
await message.answer('Вы выбрали страну ' + c['flag'], reply_markup = keyboard)
executor.start_polling(dp, skip_updates=True)
