import json from aiogram.types import InlineKeyboardMarkup, InlineKeyboardButton BASE_PATH = 'configs/timetable' FILE = f'{BASE_PATH}/groups.json' def timetable(id: int = None): keyboard = InlineKeyboardMarkup() with open(FILE, "r") as f: a = json.load(f) if id is not None: if len(id.split(",")) > 1: links = [] for i in id.split(","): if i == '': continue links.append(f"{BASE_PATH}/{i}") return links return [f"{BASE_PATH}/{id}"] for key, value in a.items(): if type(value) == type([]): tmp = '' for i in value: tmp += i tmp += "," keyboard.add(InlineKeyboardButton(key, callback_data=f"timetable|{str(tmp)}")) continue keyboard.add(InlineKeyboardButton(key, callback_data=f"timetable|{str(value)}")) return keyboard