def set_group(message): # arguments = [] # print(message.text.split(" ")[1:]) arguments = message.text.split(" ")[1:] print(arguments) arguments.insert(2, arguments.pop(0)) print(arguments) print( st.update_tg_login(arguments[0], arguments[1], arguments[2], message.chat.username)) bot.send_message( message.chat.id, st.update_tg_login(arguments[0], arguments[1], arguments[2], message.chat.username))
def message_worker(message): user_login = message.from_user.username group_num = Students.get_group_num(user_login) user_status = UserStatus.read_user_status(user_login) # print(user_status) if user_status == "Пользовательский статус ненайден" or len( user_status['data']) < 3: return command = user_status['data'][0] date = user_status['data'][1] lesson = user_status['data'][2] if not group_num: bot.send_message(message.chat.id, CommonMessages.set_group) UserStatus.del_user_status(user_login) return if message.text.lower() == "отмена": bot.send_message(message.chat.id, CommonMessages.canceled) UserStatus.del_user_status(user_login) return if command == "hometask": lesson_type = dbExt.read_schedule_lesson(group_num, date, lesson) print( HomeWork.add_home_work(group_num, date, lesson, lesson_type, message.text, user_login)) bot.send_message(message.chat.id, "ДЗ успешно добавлено.") UserStatus.del_user_status(user_login)
def set_group(message): arguments = message.text.split(" ")[1:] #print(arguments) bot.send_message( message.chat.id, st.change_group_num(arguments[0], arguments[1], arguments[2], arguments[3]))
def get_schedule(message): group = st.get_group_num(message.chat.username)["pgroup"] print(group) test = sch.read_schedule(group, "10:00-11:40 20.10.2020") print(test) bot.send_message(message.chat.id, sch.read_schedule(group, "10:00-11:40 20.10.2020"))
def scheduled_news(): students = Students.get_all_chat_ids_and_pgroup() today_date = datetime.today().date() news = NewsProvider.getNews(3) news_text = Utils.create_human_readable_news(news) weather = WeatherProvider.getWeatherForDate(today_date) weather_text = Utils.create_weather_for_today(weather) for student in students: bot.send_message(student['chatId'], f"{news_text}\n\n{weather_text}")
def set_group(message): args = Utils.get_args_from_message(message) user_login = message.from_user.username if len(args) < 3: bot.send_message(message.chat.id, CommonMessages.invalid_arguments) UserStatus.del_user_status(user_login) return response = Students.update_tg_login( args[1], args[2], args[0], message.chat.id, message.from_user.username) # name, surname, group, username bot.send_message(message.chat.id, response) UserStatus.del_user_status(user_login)
def task_list(message): user_login = message.from_user.username group_num = Students.get_group_num(user_login) today_date = datetime.today().date() if group_num: news = NewsProvider.getNews(3) news_text = Utils.create_human_readable_news(news) weather = WeatherProvider.getWeatherForDate(today_date) weather_text = Utils.create_weather_for_today(weather) bot.send_message(message.chat.id, f"{news_text}\n\n{weather_text}") else: bot.send_message(message.chat.id, CommonMessages.set_group) UserStatus.del_user_status(user_login)
def task_list(message): user_login = message.from_user.username group_num = Students.get_group_num(user_login) if group_num: homeworks = dbExt.get_home_tasks(group_num) if len(homeworks) == 0: bot.send_message(message.chat.id, f"Заданий нет.") return ln = '\n=============================\n' bot.send_message(message.chat.id, f"{ln.join(task for task in homeworks)}") else: bot.send_message(message.chat.id, CommonMessages.set_group) UserStatus.del_user_status(user_login)
def scheduled_schedule(): students = Students.get_all_chat_ids_and_pgroup() tomorrow = (datetime.today().date() + timedelta(days=1)).strftime("%d.%m.%Y") groups_schedule = {} nl = '\n' for student in students: student_group = student['pgroup'] chat_id = student['chatId'] if student_group not in groups_schedule: groups_schedule[student_group] = dbExt.get_scheduled_lessons( student_group, str(tomorrow)) if len(groups_schedule[student_group]) > 0: text = f"Привет!\nПредметы на {tomorrow}:{nl}{f'{nl}'.join(f'{lesson}' for lesson in (groups_schedule[student_group]))}" bot.send_message(chat_id, text)
def add_home_task(message): user_login = message.from_user.username group_num = Students.get_group_num(user_login) if group_num: schedule_var = dbExt.get_schedule_dates( group_num) # Add data from another module keyboards = Utils.create_keyboard_from_string_array(schedule_var, "hometask", days=True) bot.send_message(message.chat.id, "Выберите дату для домашнего задания:", reply_markup=keyboards[0]) UserStatus.del_user_status(user_login) else: bot.send_message(message.chat.id, CommonMessages.set_group) UserStatus.del_user_status(user_login)
def get_schedule(message): user_login = message.from_user.username group_num = Students.get_group_num(user_login) if group_num: schedule_var = dbExt.get_schedule_dates( group_num) # Add data from another module keyboards = Utils.create_keyboard_from_string_array(schedule_var, "schedule", days=True) bot.send_message(message.chat.id, "Выберите даты для получения расписания на число:", reply_markup=keyboards[0]) UserStatus.del_user_status(user_login) else: bot.send_message(message.chat.id, CommonMessages.set_group) UserStatus.del_user_status(user_login)
def testSt_g_G_N(): print(st.get_group_num("@Animehin"))
def get_group(message): bot.send_message(message.chat.id, st.get_group_num(message.chat.username)["pgroup"])
def testSt(): st.add_student("Stashevskii", "Ian", "3530904/70105")
def get_group(message): user_login = message.from_user.username group = Students.get_group_num(user_login) bot.send_message(message.chat.id, f"Текущая установленная группа: {group}") UserStatus.del_user_status(user_login)
def testSt_u_TG_Login(): st.update_tg_login("Stashevskii", "Ian", "3530904/70105", "@Animehin")
def callback_inline(call): args_dict = Utils.parse_callback_data( call.data) # command-name, step, text, page user_login = call.from_user.username group_num = Students.get_group_num(user_login) if not group_num: bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.id, text=CommonMessages.set_group) # schedule and hometask pages check, also schedule day selection included if args_dict['command'] == 'schedule' or ( args_dict['command'] == 'hometask' and args_dict['step'] == '0'): if args_dict['text'] == "👉🏿": schedule_var = dbExt.get_schedule_dates( group_num) # Add data from another module keyboards = Utils.create_keyboard_from_string_array( schedule_var, args_dict['command'], days=True) bot.edit_message_text( chat_id=call.message.chat.id, message_id=call.message.id, text=call.message.text, reply_markup=keyboards[int(args_dict['page']) + 1]) return elif args_dict['text'] == "👈🏿": schedule_var = dbExt.get_schedule_dates( group_num) # Add data from another module keyboards = Utils.create_keyboard_from_string_array( schedule_var, args_dict['command'], days=True) bot.edit_message_text( chat_id=call.message.chat.id, message_id=call.message.id, text=call.message.text, reply_markup=keyboards[int(args_dict['page']) - 1]) return if args_dict['command'] == 'schedule': schedule = dbExt.get_scheduled_lessons(group_num, args_dict['text']) nl = '\n' time_key = 'time' class_key = 'scheduledClass' bot.edit_message_text( chat_id=call.message.chat.id, message_id=call.message.id, text= f"Предметы на {args_dict['text']}:{nl}{f'{nl}'.join(f'{lesson[time_key]}: {lesson[class_key]}' for lesson in schedule)}" ) return if args_dict['command'] == 'hometask': if args_dict['step'] == '0': schedule = Utils.get_lessons_name_from_schedule( dbExt.get_scheduled_lessons(group_num, args_dict['text'])) keyboards = Utils.create_keyboard_from_string_array( schedule, args_dict['command'], stage=1) bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.id, text=f"Выберите из списка предметов:", reply_markup=keyboards[0]) UserStatus.add_user_status( user_login, args_dict['step'], [args_dict['command'], args_dict['text']]) return if args_dict['step'] == '1': status = UserStatus.read_user_status(user_login) command = status['data'][0] date = status['data'][1] if command != 'hometask': bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.id, text=call.message.text) bot.send_message(call.message.chat.id, CommonMessages.invalid_button) UserStatus.del_user_status(user_login) return bot.edit_message_text( chat_id=call.message.chat.id, message_id=call.message.id, text=f"Выбран предмет:\n{args_dict['text']} на {date}.\n" f"Отправьте текст задания сообщением.\nДля отмены введите 'Отмена'" ) UserStatus.add_user_status(user_login, args_dict['step'], [command, date, args_dict['text']]) pass