Added timetable #6

Merged
tema merged 1 commits from testing into master 2023-02-19 01:53:48 +03:00
8 changed files with 83 additions and 3 deletions

2
.gitignore vendored
View File

@ -10,6 +10,8 @@ __pycache__/
*.ini
!example_config.ini
*.json
!configs/timetable/groups.json
*.jpg
*.db
*.sqlite3
*.txt

View File

@ -0,0 +1,11 @@
{
"1, 121, 12c": "1.jpg",
"131, 13c, 141, 14c": "2.jpg",
"3, 411, 42c, 431": "3.jpg",
"43c": "4.jpg",
"4, 521, 52c, 531": "5.jpg",
"53c, 541, 54c": "6.jpg",
"2, 221, 22c, 231": "7.jpg",
"23c, 241, 24c": "8.jpg",
"411, 421, 431": ["9.jpg","10.jpg"]
}

View File

@ -1 +1,2 @@
from . import main
from . import timetable

View File

@ -7,7 +7,7 @@ from keyboards.inline.keyboard import cancel_button, menu
from parser import get_about_replacements
@dp.callback_query_handler(lambda c: c.data != "back")
@dp.callback_query_handler(lambda c: c.data != "back" and not len(c.data.split("|")) == 2)
async def callback_query(query: types.CallbackQuery):
from_user = query.from_user
data = get_about_replacements()

View File

@ -0,0 +1,21 @@
import io
import json
from aiogram import types
from load import dp, bot
from keyboards.inline.timetable import timetable
@dp.callback_query_handler(lambda c: c.data.split("|")[0] == "timetable")
async def callback_table(query: types.CallbackQuery):
message = query.message
group = query.data.split("|")[1]
file = timetable(group)
for f in file:
await bot.send_photo(
message.chat.id,
io.BytesIO(open(f, 'rb').read())
)
await query.answer()

View File

@ -1,2 +1,3 @@
from . import main
from . import admin
from . import timetable

View File

@ -0,0 +1,10 @@
from aiogram import types
from load import dp, bot
from keyboards.inline.timetable import timetable
@dp.message_handler(commands='timetable')
async def get_table(message: types.Message):
markup = timetable()
await bot.send_message(message.chat.id, "q", reply_markup=markup)

View File

@ -0,0 +1,34 @@
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