replace-bot/keyboards/inline/timetable.py

34 lines
935 B
Python
Raw Permalink Normal View History

2023-02-19 01:51:52 +03:00
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