def notifying_lectures_process(bot): log_text('Starting to notify about upcoming lectures..') while True: if time_helpers.current_time_in_minutes( ) >= 60 and time_helpers.current_time_in_minutes() <= 480: continue chats = get_all_chats_info() for chat in chats: notify_minutes = chat['schedule_notify_minutes'] if notify_minutes == 0: continue chat_id = chat['chat_id'] schedule = chat['schedule'] current_day = time_helpers.current_day() current_minutes = time_helpers.current_time_in_minutes() if not current_day in schedule: continue for subject in schedule[current_day]: subject_start_time = time_helpers.am_to_pm( subject['start_time']) if subject_start_time - current_minutes == notify_minutes: right_word = 'минут' if (notify_minutes % 10 == 1): right_word = 'минуту' elif (notify_minutes % 10 > 1 and notify_minutes % 10 < 5): right_word = 'минуты' if notify_minutes % 100 > 10 and notify_minutes % 100 < 20: right_word = 'минут' message = 'Урок ровно через <b>{} {}</b>, не опоздай 😉\n\n'.format( notify_minutes, right_word) message = message + '{}\n{} - {}\n{}\n'.format( subject['course_name'], subject['start_time'], subject['end_time'], subject['lecture_room']) send_message(bot, chat_id=chat_id, text=message) time.sleep(60)
def notifying_webworks_process(bot): while True: if time_helpers.current_time_in_minutes( ) >= 0 and time_helpers.current_time_in_minutes() <= 719: continue log_text('Starting to notify about new webworks..') chats = get_all_chats_info() for chat in chats: if chat['notify_webworks']: try: chat_id = chat['chat_id'] check_new_webworks(bot, chat_id) except: log_text('Webworks exception occured but still running..') pass time.sleep(14400)
def next_lecture(bot, update): chat_id = update.message.chat_id send_chatting_action(bot, chat_id) chat_info = api_calls.get_chat_info(chat_id) if not 'schedule' in chat_info: send_message(bot, chat_id=chat_id, text=bot_messages.no_schedule_response) else: log_text('{} used /next_lecture command'.format(chat_info['username'])) schedule = chat_info['schedule'] current_day = time_helpers.current_day() current_time = time_helpers.current_time_in_minutes() if not current_day in schedule: schedule[current_day] = [] for subject in schedule[current_day]: start_time = time_helpers.am_to_pm(subject['start_time']) if start_time > current_time: message = '<b>{}</b>\n\n'.format(current_day) message = message + '{}\n{} - {}\n{}\n'.format( subject['course_name'], subject['start_time'], subject['end_time'], subject['lecture_room']) send_message(bot, chat_id=chat_id, text=message) return days = time_helpers.days day_index = days.index(current_day) for index in range(0, len(days)): next_index = (day_index + index + 1) % 7 next_day = days[next_index] if not next_day in schedule: continue for subject in schedule[next_day]: start_time = time_helpers.am_to_pm(subject['start_time']) message = '<b>{}</b>\n\n'.format(next_day) message = message + '{}\n{} - {}\n{}\n'.format( subject['course_name'], subject['start_time'], subject['end_time'], subject['lecture_room']) send_message(bot, chat_id=chat_id, text=message) return