def get_lessons(self, email, date_start='', date_end='', sender_id=0, other_email=''): if other_email != '': if date_start != '' and date_end != '': response = ruz.person_lessons(other_email, date_start, date_end) else: response = ruz.person_lessons(other_email) else: if date_start != '' and date_end != '': response = ruz.person_lessons(email.replace('miem.hse.ru', check_csv(sender_id)), date_start, date_end) else: response = ruz.person_lessons(email.replace('miem.hse.ru', check_csv(sender_id))) message = '' curr_date = '' print('LESSSSSSONS: \n', response) for lesson in response: if curr_date != lesson['date']: message += DaysOfWeek[lesson['dayOfWeekString']] + ':: ' + lesson['date'] + '\n' curr_date = lesson['date'] message += str(lesson['lessonNumberStart']) + ' пара (' + \ lesson['beginLesson'] + '-' + lesson['endLesson'] + ')\n' +\ lesson['discipline'] + '\n' + \ lesson['kindOfWork'] + '\n' + \ lesson['auditorium'] + ' (' + lesson['building'] + ')' + '\n' +\ lesson['lecturer'] + '\n\n' self.send_msg(email, message)
def get_lessons(email, date_start='', date_end='', sender_id=0, other_email=''): if other_email == '404': return 'Таких пользователей несколько. Попробуйте вместо упоминания использовать почту человека.' if other_email != '': if date_start != '' and date_end != '': response = ruz.person_lessons(other_email, date_start, date_end) else: response = ruz.person_lessons(other_email) else: checked_user = check_user.check(email) if checked_user: if date_start != '' and date_end != '': response = ruz.person_lessons(checked_user, date_start, date_end) else: response = ruz.person_lessons(checked_user) else: return 'В базе отсутствует такой пользователь(' message = '' curr_date = '' if not response: return 'Запрос ничего не выдал(. Перепроверьте ваше сообщение. Если все в порядке, то есть два варианта: каникулы или лег руз:)' for lesson in response: if curr_date != lesson['date']: message += DaysOfWeek[ lesson['dayOfWeekString']] + ':: ' + lesson['date'] + '\n' curr_date = lesson['date'] message += str(lesson['lessonNumberStart']) + ' пара (' + \ lesson['beginLesson'] + '-' + lesson['endLesson'] + ')\n' + \ lesson['discipline'] + '\n' + \ lesson['kindOfWork'] + '\n' if datetime.datetime.strptime(lesson['date'], '%Y.%m.%d').date() < datetime.date( 2020, 3, 17): message += lesson['auditorium'] + ' (' + lesson[ 'building'] + ')' + '\n' else: if lesson['url1']: message += 'Видеочат: ' + lesson['url1'] + '\n' message += lesson['lecturer'] + '\n\n' return message
def check_email(message): global schedule pttrn = ",\s'text':\s'([^']+)" mail = re.findall(pttrn, str(message))[0] check = ruz.utils.is_valid_hse_email(mail) if not check: msg = bot.send_message( message.chat.id, 'This address is incorrect. Please enter a valid HSE e-mail.') bot.register_next_step_handler(msg, check_email) else: schedule = ruz.person_lessons(mail) if schedule: get_schedule(message) else: msg = bot.send_message( message.chat.id, 'Could not find the schedule for this e-mail address. Please check your spelling and try again.' ) bot.register_next_step_handler(msg, check_email)
def test_schedule(): logging.warning("Trusted emails may be deactivated in few years!") _test_schema(schema=RESPONSE_SCHEMA['schedule'], response=ruz.person_lessons(email=TRUSTED_EMAILS['student']))