def get_my_progress(call): grades_dict = {} for grade in Grade.get_grades_by_student(student_id=call.from_user.id): subject = Subject.get_subject_fullname_by_id(grade.subject_id) grade_type = GradeType.get_gradetype_by_id(grade.gradetype_id) ects = grade.ects grade = grade.grade grades_dict.setdefault(subject, []).append(f' {grade_type}: {grade} ({ects})\n') grades = '<b>Оцінки</b>:\n\n' for subject in grades_dict: grades += ''.join( f'<i>{subject}:</i>\n{"".join(grades_dict[subject])}\n') debts = '<b>Борги</b>: ' debts += ', '.join([ Subject.get_subject_fullname_by_id(debt.subject_id) for debt in SubjectDebtor.get_debt_by_student( student_id=call.from_user.id) ]) bot.edit_message_text(chat_id=call.from_user.id, message_id=call.message.message_id, text=grades + debts, parse_mode='html')
def get_event_info(call): event_id = call.data.split('_')[1] event = Event.get_event(event_id) message = f'<b> {event.name} </b>\n' \ f'Місце проведення: {event.place}\n' \ f'Дата: {event.date}\n' \ f'Час: {event.time}' if EventVisitor.check_visitor(event_id=event_id, student_id=call.from_user.id) is False: keyboard = InlineKeyboardMarkup() keyboard.add( InlineKeyboardButton( text= f'{emojize(":pencil2:", use_aliases=True)} Зареєструватися', callback_data=f'regon_{event.id}')) bot.edit_message_text(chat_id=call.from_user.id, message_id=call.message.message_id, text=message, reply_markup=keyboard, parse_mode='html') else: keyboard = InlineKeyboardMarkup() keyboard.add( InlineKeyboardButton( text=f'{emojize(":x:", use_aliases=True)} Відмінити реєстрацію', callback_data=f'cancelregevent_{event.id}')) bot.edit_message_text(chat_id=call.from_user.id, message_id=call.message.message_id, text=message, reply_markup=keyboard, parse_mode='html')
def get_subject(call): subjects_keyboard = make_keyboard('subject', Subject.get_subjects(), 'getfilesubject_') bot.edit_message_text(chat_id=call.from_user.id, message_id=call.message.message_id, text='Вибери предмет:', reply_markup=subjects_keyboard)
def get_student_for_extragrade(call): student_id = call.data.split('_')[1] bot.edit_message_text(chat_id=call.from_user.id, message_id=call.message.message_id, text='Введи додатковий бал (1-10)') bot.register_next_step_handler_by_chat_id(call.from_user.id, save_extragrade, student_id)
def choose_cathedra(message): cathedra_keyboard = make_keyboard(keyboard_type='cathedra', elem_list=Cathedra.get_cathedras(), marker='teachercathedra_') bot.edit_message_text(chat_id=message.from_user.id, message_id=message.message.message_id, text='Вибери кафедру:', reply_markup=cathedra_keyboard)
def show_employment_info(call): bot.edit_message_text( chat_id=call.from_user.id, message_id=call.message.message_id, text= '<b>Центр сприяння працевлаштуванню студентів та випускників</b>\n\n' '<b>Начальник:</b> Ігнашова Анастасія Вікторівна\n' '<b>тел.:</b> +380(61)7698599', parse_mode='html')
def get_event_for_del(call): event_keyboard = make_keyboard(keyboard_type='event', elem_list=Event.get_all_events(), marker='eventdelete_') bot.edit_message_text(chat_id=call.from_user.id, message_id=call.message.message_id, text='Який захід видалити?', reply_markup=event_keyboard)
def get_event_visitors(call): event_keyboard = make_keyboard(keyboard_type='event', elem_list=Event.get_all_events(), marker='eventvisitor_') bot.edit_message_text(chat_id=call.from_user.id, message_id=call.message.message_id, text='Учасники якого заходу?', reply_markup=event_keyboard)
def show_site(call): site_keyboard = InlineKeyboardMarkup() site_keyboard.add( InlineKeyboardButton(text='https://zp.edu.ua', url='https://zp.edu.ua')) bot.edit_message_text(chat_id=call.from_user.id, message_id=call.message.message_id, text='Сайт НУ «ЗП»', reply_markup=site_keyboard)
def show_profcom_info(call): bot.edit_message_text( chat_id=call.from_user.id, message_id=call.message.message_id, text='<b>Профком студентів, аспірантів та докторантів</b>\n\n' '<b>Голова профкому:</b> Іванченко Андрій Володимирович\n' '<b>тел.:</b> +380(61)7698507\n\n' '<b>Заступник голови:</b> Зінченко Марина Михайлівна\n' '<b>тел.:</b> +380(61)7698340', parse_mode='html')
def delete_event(call): event_id = call.data.split('_')[1] bot.edit_message_text( chat_id=call.from_user.id, message_id=call.message.message_id, text=f'Захід {Event.get_event(event_id).name} видалено ' f'{emojize(":white_check_mark:", use_aliases=True)}') Event.delete_event(event_id)
def get_subject_for_grade(call): subject_id = call.data.split('_')[1] grade_type_keyboard = make_keyboard('gradetype', GradeType.get_gradetypes(), f'gradetype_{subject_id}_') bot.edit_message_text(chat_id=call.from_user.id, message_id=call.message.message_id, text='Виберіть тип оцінки:', reply_markup=grade_type_keyboard)
def get_grade_type(call): subject_id = call.data.split('_')[1] grade_type_id = call.data.split('_')[2] group_keyboard = make_keyboard( 'student', Group.get_groups()[:4], f'studentsgroup_{subject_id}_{grade_type_id}_') bot.edit_message_text(chat_id=call.from_user.id, message_id=call.message.message_id, text='Виберіть групу:', reply_markup=group_keyboard)
def get_teacher_info(call): teacher_id = call.data.split('_')[1] teacher = Teacher.get_teacher_by_id(teacher_id) message_text = f'<b><a href="{teacher.site}">' \ f'{teacher.name}</a></b>\n\n' \ f'<b>e-mail:</b> {teacher.email}\n' \ bot.edit_message_text(chat_id=call.from_user.id, message_id=call.message.message_id, text=message_text, parse_mode='html', disable_web_page_preview=True)
def choose_teacher(call): cathedra_id = call.data.split('_')[1] teachers_info_keyboard = make_keyboard( keyboard_type='teacher', elem_list=Teacher.get_teachers_by_cathedra(cathedra_id), marker='showteacher_') bot.edit_message_text(chat_id=call.from_user.id, message_id=call.message.message_id, text='Викладачі кафедри', reply_markup=teachers_info_keyboard, parse_mode='html')
def cancel_reg_on_event(call): event_id = call.data.split('_')[1] EventVisitor.delete_visitor(event_id, call.from_user.id) bot.edit_message_text( chat_id=call.from_user.id, message_id=call.message.message_id, text= f'Реєстрація скасована {emojize(":white_check_mark:", use_aliases=True)}' ) user = Student.get_student_by_id(call.from_user.id)
def send_student_events_file(call): file_name = 'Відвідування заходів' file_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + '/tmp/' group_dict = prepare_student_events_table() make_student_events_table(group_dict=group_dict, file_name=file_name, file_path=file_path) doc = open(f'{file_path}{file_name}.xlsx', 'rb') bot.edit_message_text(chat_id=call.from_user.id, message_id=call.message.message_id, text='Документ з відвідуваннями заходів:') bot.send_document(chat_id=call.from_user.id, data=doc)
def send_event_visitors_file(call): event_id = call.data.split('_')[1] event_name = Event.get_event(event_id).name file_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + '/tmp/' stud_dict, otherfac_list = prepare_event_visitors_table(event_id) make_event_visitors_table(visitors_dict=stud_dict, otherfac_list=otherfac_list, event_name=event_name, file_path=file_path) doc = open(f'{file_path}{event_name}.xlsx', 'rb') bot.edit_message_text(chat_id=call.from_user.id, message_id=call.message.message_id, text='Документ з учасниками:') bot.send_document(chat_id=call.from_user.id, data=doc)
def show_accounting_info(call): props_keyboard = InlineKeyboardMarkup() props_keyboard.add( InlineKeyboardButton(text='Завантажити файл', callback_data='send_props')) bot.edit_message_text( chat_id=call.from_user.id, message_id=call.message.message_id, text= '<b>Відділ бухгалтерського обліку та звітності, економіки, розподілу асигнувань</b>\n\n' '<b>Приймальня:</b> Оніщенко Ірина Миколаївна\n' '<b>тел.:</b> +380(61)7698368\n\n' f'Щоб отримати платіжні реквізити, натисни {emojize(":point_down:", use_aliases=True)}', reply_markup=props_keyboard, parse_mode='html')
def get_profcomdebtor_for_add(call): group = call.data.split('_')[1] debtor_id = call.data.split('_')[2] if ProfcomDebtor.debtor_exists(debtor_id): bot.edit_message_text(chat_id=call.from_user.id, message_id=call.message.message_id, text='Студент вже занесений до боржників') bot.send_message(chat_id=call.from_user.id, text='Вибери пункт меню:', reply_markup=make_role_replykeyboard(studdekan_buttons)) else: bot.edit_message_text(chat_id=call.from_user.id, message_id=call.message.message_id, text='Введи борг студента') bot.register_next_step_handler_by_chat_id(call.from_user.id, save_profcomdebtor, debtor_id, group)
def change_headman(call): group = call.data.split('_')[1] new_headman_id = call.data.split('_')[2] Headman.change_headman(new_headman_id) username = Student.get_student_by_id(new_headman_id).username name = Student.get_student_by_id(new_headman_id).name bot.edit_message_text(chat_id=call.from_user.id, message_id=call.message.message_id, text=f'<a href="t.me/{username}">{name}</a> ' f'призначений старостою групи {group} ' f'{emojize(":white_check_mark:", use_aliases=True)}', parse_mode='html') bot.send_message(chat_id=call.from_user.id, text='Вибери пункт меню:', reply_markup=make_role_replykeyboard(studdekan_buttons))
def get_subject_for_share(call): subject_id = call.data.split('_')[1] message = bot.edit_message_text(chat_id=call.from_user.id, message_id=call.message.message_id, text='Відправте файл або повідомлення боту і він його передасть ' 'всім студентам цього предмету ' f'{emojize(":incoming_envelope:", use_aliases=True)}') bot.register_next_step_handler(message, send_message_or_file, subject_id)
def get_study_methods(call): subject_id = call.data.split('_')[1] subject_name = Subject.get_subject_name_by_id(subject_id) subject_path = os.path.dirname( os.path.dirname(os.path.dirname( os.path.abspath(__file__)))) + f'/tmp/{subject_name}' if os.path.exists(subject_path) and os.listdir(subject_path): bot.edit_message_text( chat_id=call.from_user.id, message_id=call.message.message_id, text=f'Методичні матеріали по предмету {subject_name}') for file_name in next(os.walk(subject_path))[2]: doc = open(f'{subject_path}/{file_name}', 'rb') bot.send_document(chat_id=call.from_user.id, data=doc) else: bot.edit_message_text(chat_id=call.from_user.id, message_id=call.message.message_id, text='Методичних матеріалів немає')
def get_profcomdebtor_for_del(call): debtor_id = call.data.split('_')[1] group = Group.get_group_by_id(Student.get_student_by_id(debtor_id).group_id) username = Student.get_student_by_id(debtor_id).username name = Student.get_student_by_id(debtor_id).name bot.edit_message_text(chat_id=call.from_user.id, message_id=call.message.message_id, text=f'Студент <a href="t.me/{username}">{name}</a> ' f'групи {group} видалений з боржників ' f'{emojize(":heavy_exclamation_mark:", use_aliases=True)}', parse_mode='html', disable_web_page_preview=True) ProfcomDebtor.delete_debtor(debtor_id) bot.send_message(chat_id=call.from_user.id, text='Вибери пункт меню:', reply_markup=make_role_replykeyboard(studdekan_buttons))
def list_headman(call): headmans_list = Headman.get_all_headmans() message_text = f'<b>Старости {len(headmans_list)}/52:</b>\n\n' for group in Group.get_groups(): headman = Headman.get_headman_by_group(group_id=group.id) if headman: student = Student.get_student_by_id(headman.student_id) link = f'<a href="t.me/{student.username}">{get_fio(student.name)}</a> ({headman.rating})\n' else: link = '-\n' message_text += ''.join(f'КНТ-{group.name}: {link}') bot.edit_message_text(chat_id=call.from_user.id, message_id=call.message.message_id, text=message_text, parse_mode='html', disable_web_page_preview=True)
def show_parameters_to_change(call): event_id = call.data.split('_')[1] change_event_keyboard = InlineKeyboardMarkup() change_event_keyboard.add( InlineKeyboardButton(text='Назва заходу', callback_data=f'name_{event_id}')) change_event_keyboard.add( InlineKeyboardButton(text='Місце проведення', callback_data=f'place_{event_id}')) change_event_keyboard.add( InlineKeyboardButton(text='Дата проведення', callback_data=f'date_{event_id}')) change_event_keyboard.add( InlineKeyboardButton(text='Час проведення', callback_data=f'time_{event_id}')) bot.edit_message_text( chat_id=call.from_user.id, message_id=call.message.message_id, text= f'Що потрібно змінити в заході {Event.get_event(event_id=event_id).name}?', reply_markup=change_event_keyboard)
def get_parameter_to_change(call): event_id = call.data.split('_')[1] if call.data.startswith('name_'): message = bot.edit_message_text(chat_id=call.from_user.id, message_id=call.message.message_id, text='Нова назва') bot.register_next_step_handler(message, change_event_name, event_id) elif call.data.startswith('place_'): message = bot.edit_message_text(chat_id=call.from_user.id, message_id=call.message.message_id, text='Нове місце') bot.register_next_step_handler(message, change_event_place, event_id) elif call.data.startswith('date_'): message = bot.edit_message_text(chat_id=call.from_user.id, message_id=call.message.message_id, text='Нова дата') bot.register_next_step_handler(message, change_event_date, event_id) elif call.data.startswith('time_'): message = bot.edit_message_text(chat_id=call.from_user.id, message_id=call.message.message_id, text='Новий час') bot.register_next_step_handler(message, change_event_time, event_id)
def register_on_event(call): event_id = call.data.split('_')[1] chat_id = call.from_user.id if Group.get_group_by_id( Student.get_student_by_id(chat_id).group_id) == 'other': message = bot.send_message( chat_id=chat_id, text="Введіть прізвище ім'я факультет групу\n" "<b>Наприклад:</b> <i>Петров Петро ФЕУ 123</i>", parse_mode='html') bot.register_next_step_handler(message, reg_on_event_other, event_id) else: EventVisitor.add_visitor(event_id, chat_id) bot.edit_message_text( chat_id=chat_id, message_id=call.message.message_id, text= f'Реєстрація пройшла успішно {emojize(":white_check_mark:", use_aliases=True)}' ) user = Student.get_student_by_id(chat_id)
def get_cathedra_info(call): cathedra_id = call.data.split('_')[1] cathedra = Cathedra.get_cathedra_by_id(cathedra_id) # bot.send_message(chat_id=374464076, text=f'#asked_cathedra {cathedra.name}') teachers_button = InlineKeyboardMarkup() message_text = '' if cathedra_id == '1': message_text = f'<b><a href="{cathedra.site}">Кафедра програмних засобів</a></b>\n\n' \ '<b>кабінет:</b> 43 \n' \ '<b>тел.:</b> +380(61)7698267\n' \ '<b>e-mail:</b> [email protected]\n\n' \ '<b>Завідувач кафедри</b>\n' \ '<a href="https://zp.edu.ua/sergiy-oleksandrovich-subbotin">' \ 'Субботін Сергій Олександрович</a>\n\n' \ '<b>тел.:</b> +380(61)7646330\n' \ '<b>e-mail:</b> [email protected]' teachers_button.add( InlineKeyboardButton(text='Викладачі кафедри', callback_data=f'teachersinfo_{cathedra_id}')) elif cathedra_id == '2': message_text = f'<b><a href="{cathedra.site}">' \ f'Кафедра системного аналізу та обчислювальної математики</a></b>\n\n' \ '<b>кабінет:</b> 361\n' \ '<b>тел.:</b> +380(61)7698267\n' \ '<b>e-mail:</b> [email protected]\n\n' \ '<b>Завідувач кафедри</b>\n' \ '<a href="https://zp.edu.ua/?q=node/3110">Корніч Григорій Володимирович</a>\n\n' \ '<b>кабінет:</b> 361, 231a\n' \ '<b>тел.:</b> +380(61)7698247\n' \ '<b>e-mail:</b> [email protected]' teachers_button.add( InlineKeyboardButton(text='Викладачі кафедри', callback_data=f'teachersinfo_{cathedra_id}')) elif cathedra_id == '3': message_text = f'<b><a href="{cathedra.site}">' \ f'Кафедра вищої математики</a></b>\n\n' \ '<b>кабінет:</b> 216\n' \ '<b>тел.:</b> +380(61)7698446\n' \ '<b>e-mail:</b> [email protected]\n\n' \ '<b>Завідувач кафедри</b>\n' \ '<a href="https://zp.edu.ua/?q=node/3450">Володимир Михайлович Онуфрієнко</a>\n\n' \ '<b>кабінет:</b> 201\n' \ '<b>тел.:</b> +380(61)7646575; +380(61)7698487\n' teachers_button.add( InlineKeyboardButton( text='Викладачі кафедри', url= 'https://zp.edu.ua/spisok-spivrobitnikiv-kafedri-vishchoyi-matematiki' )) elif cathedra_id == '4': message_text = f'<b><a href="{cathedra.site}">' \ f'Кафедра фізики</a></b>\n\n' \ '<b>кабінет:</b> 328\n' \ '<b>тел.:</b> +380(61)7698490\n' \ '<b>e-mail:</b> [email protected]\n\n' \ '<b>Завідувач кафедри</b>\n' \ '<a href="https://zp.edu.ua/?q=node/622">Степан Васильович Лоскутов</a>\n\n' \ '<b>кабінет:</b> 324\n' \ '<b>тел.:</b> +38(061)7698355\n' \ '<b>e-mail:</b> [email protected]' teachers_button.add( InlineKeyboardButton( text='Викладачі кафедри', url= 'https://zp.edu.ua/vikladachi-ta-spivrobitniki-kafedri-fizika') ) elif cathedra_id == '5': message_text = f'<b><a href="{cathedra.site}">' \ f'Кафедра іноземних мов</a></b>\n\n' \ '<b>кабінет:</b> 348\n' \ '<b>тел.:</b> +380(61)7698248\n' \ '<b>e-mail:</b> [email protected]\n\n' \ '<b>Завідувач кафедри</b>\n' \ '<a href="https://zp.edu.ua/?q=node/622">Соболь Юлія Олександрівна</a>\n\n' \ '<b>кабінет:</b> 330-Б\n' \ '<b>тел.:</b> +380(61)7698522\n' \ '<b>e-mail:</b> [email protected]' teachers_button.add( InlineKeyboardButton( text='Викладачі кафедри', url= 'https://zp.edu.ua/vykladachi-ta-spivrobitnyky-kafedry-inozemnyh-mov' )) elif cathedra_id == '6': message_text = f'<b><a href="{cathedra.site}">' \ f'Кафедра українознавства та загальної мовної підготовки</a></b>\n\n' \ '<b>кабінет:</b> 269\n' \ '<b>тел.:</b> +38(061)7642314\n' \ '<b>e-mail:</b> [email protected]\n\n' \ '<b>Завідувач кафедри</b>\n' \ '<a href="https://zp.edu.ua/?q=node/1190">Шаповалов Георгій Іванович</a>\n\n' \ '<b>кабінет:</b> 270\n' \ '<b>тел.:</b> +38(061)7698336; +38(061)7698375\n' \ '<b>e-mail:</b> [email protected]' elif cathedra_id == '7': message_text = f'<b><a href="{cathedra.site}">' \ f"Кафедра комп'ютерних систем та мереж</a></b>\n\n" \ '<b>кабінет:</b> 53-Б\n' \ '<b>тел.:</b> +380(61)698249\n' \ '<b>e-mail:</b> [email protected]\n\n'\ '<b>Завідувач кафедри</b>\n' \ '<a href="https://zp.edu.ua/?q=node/2726">Равіль Камілович Кудерметов</a>\n\n' \ '<b>кабінет:</b> 53-Б\n' \ '<b>тел.:</b> +380(61)698249\n' teachers_button.add( InlineKeyboardButton( text='Викладачі кафедри', url='https://zp.edu.ua/vikladachi-ta-spivrobitniki-kafedri-ksm' )) bot.edit_message_text(chat_id=call.from_user.id, message_id=call.message.message_id, text=message_text, reply_markup=teachers_button, parse_mode='html', disable_web_page_preview=True)
def search_aud_again(call): message = bot.edit_message_text(chat_id=call.from_user.id, message_id=call.message.message_id, text=f'Введи номер потрібної аудиторії') bot.register_next_step_handler(message, get_aud)