testing #11
2
.gitignore
vendored
2
.gitignore
vendored
@ -10,6 +10,8 @@ __pycache__/
|
|||||||
*.ini
|
*.ini
|
||||||
!example_config.ini
|
!example_config.ini
|
||||||
*.json
|
*.json
|
||||||
|
!configs/timetable/groups.json
|
||||||
|
*.jpg
|
||||||
*.db
|
*.db
|
||||||
*.sqlite3
|
*.sqlite3
|
||||||
*.txt
|
*.txt
|
||||||
|
11
configs/timetable/groups.json
Normal file
11
configs/timetable/groups.json
Normal 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"]
|
||||||
|
}
|
@ -1 +1,2 @@
|
|||||||
from . import main
|
from . import main
|
||||||
|
from . import timetable
|
@ -7,7 +7,7 @@ from keyboards.inline.keyboard import cancel_button, menu
|
|||||||
from parser import get_about_replacements
|
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):
|
async def callback_query(query: types.CallbackQuery):
|
||||||
from_user = query.from_user
|
from_user = query.from_user
|
||||||
data = get_about_replacements()
|
data = get_about_replacements()
|
||||||
|
21
handlers/callback/timetable.py
Normal file
21
handlers/callback/timetable.py
Normal 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()
|
@ -1,2 +1,3 @@
|
|||||||
from . import main
|
from . import main
|
||||||
from . import admin
|
from . import admin
|
||||||
|
from . import timetable
|
10
handlers/private/timetable.py
Normal file
10
handlers/private/timetable.py
Normal 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)
|
34
keyboards/inline/timetable.py
Normal file
34
keyboards/inline/timetable.py
Normal 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
|
Loading…
Reference in New Issue
Block a user