Exemplo n.º 1
0
def handle_text(message):
    user_position = UserPosition(database_url).back_keyboard(
        str(message.chat.id))
    if user_position == 1:
        UserPosition(database_url).cancel_getting_started(str(message.chat.id))
        keyboard.main_menu(message)

    if user_position == 2:
        UserPosition(database_url).cancel_faculty(str(message.chat.id))
        keyboard.get_all_faculties(message)

    if user_position == 3:
        UserPosition(database_url).cancel_course(str(message.chat.id))
        faculty = UserPosition(database_url).verification(str(message.chat.id))
        if faculty != "Загальні підрозділи" and faculty != 'Заочне навчання':
            keyboard.stable_six_courses(message)

        if faculty == "Загальні підрозділи":
            keyboard.stable_one_course(message)

        if faculty == "Заочне навчання":
            keyboard.stable_three_courses(message)

    if user_position == 4:
        UserPosition(database_url).cancel_group(str(message.chat.id))
        faculty, course = UserPosition(database_url).get_faculty_and_course(
            str(message.chat.id))
        groups_list = Timetable(database_url).get_all_groups(faculty, course)
        groups_list.sort()
        keyboard.group_list_by_faculty_and_group(groups_list, message)
Exemplo n.º 2
0
def handle_text(message):
    UserPosition(database_url).set_course_position(str(message.chat.id),
                                                   message.text[:1])
    faculty, course = UserPosition(database_url).get_faculty_and_course(
        str(message.chat.id))
    groups_list = Timetable(database_url).get_all_groups(faculty, course)
    groups_list.sort()
    keyboard.group_list_by_faculty_and_group(groups_list, message)
Exemplo n.º 3
0
def handle_text(message):
    today, tomorrow = CurrentDates(database_url).get_dates()
    group = UserPosition(database_url).verification(str(message.chat.id))
    weekday_index = datetime.datetime.strptime(today,
                                               '%d.%m.%Y').date().weekday()

    if message.text == 'На сегодня':
        lessons = Timetable(database_url).get_lessons(group, today)
        lessons = [lessons[key] for key in sorted(lessons.keys())]

        if weekday_index == 5:
            bot.send_message(message.chat.id, 'Выходной день')
        elif weekday_index == 6:
            bot.send_message(message.chat.id, 'Выходной день')
        else:
            bot.send_message(message.chat.id,
                             'Расписание на сегодня ({0}):'.format(today[:5]))
            bot.send_message(message.chat.id, display_schedule(lessons))

    if message.text == 'На завтра':
        lessons = Timetable(database_url).get_lessons(group, tomorrow)
        lessons = [lessons[key] for key in sorted(lessons.keys())]

        if weekday_index == 4:
            bot.send_message(message.chat.id, 'Выходной день')
        elif weekday_index == 5:
            bot.send_message(message.chat.id, 'Выходной день')
        else:
            bot.send_message(
                message.chat.id,
                'Расписание на завтра ({0}):'.format(tomorrow[:5]))
            bot.send_message(message.chat.id, display_schedule(lessons))

    if message.text == 'Подписаться на эту группу':
        Subscribers(database_url).create_subscribers()
        Subscribers(database_url).add_subscriber(str(message.chat.id), group)
        bot.send_message(message.chat.id,
                         'Вы подписались на группу {0}.'.format(group))
Exemplo n.º 4
0
def handle_text(message):
    CurrentDates(database_url).add_dates('26.03.2017', '27.03.2017')
    group = Subscribers(database_url).get_subscriber_group(str(
        message.chat.id))
    today, tomorrow = CurrentDates(database_url).get_dates()
    weekday_index = datetime.datetime.strptime(today,
                                               '%d.%m.%Y').date().weekday()

    lessons = Timetable(database_url).get_lessons(group, today)
    lessons_today = [lessons[key] for key in sorted(lessons.keys())]

    lessons = Timetable(database_url).get_lessons(group, tomorrow)
    lessons_tomorrow = [lessons[key] for key in sorted(lessons.keys())]

    if weekday_index == 4:
        bot.send_message(message.chat.id,
                         'Расписание на сегодня ({0}):'.format(today[:5]))
        bot.send_message(message.chat.id, display_schedule(lessons_today))
        bot.send_message(message.chat.id,
                         'Расписание на завтра ({0}):'.format(tomorrow[:5]))
        bot.send_message(message.chat.id, 'Выходной день.')
    elif weekday_index == 5:
        bot.send_message(message.chat.id, 'Выходные дни.')
    elif weekday_index == 6:
        bot.send_message(message.chat.id,
                         'Расписание на сегодня ({0}):'.format(today[:5]))
        bot.send_message(message.chat.id, 'Выходной день.')
        bot.send_message(message.chat.id,
                         'Расписание на завтра ({0}):'.format(tomorrow[:5]))
        bot.send_message(message.chat.id, display_schedule(lessons_tomorrow))
    else:
        bot.send_message(message.chat.id,
                         'Расписание на сегодня ({0}):'.format(today[:5]))
        bot.send_message(message.chat.id, display_schedule(lessons_today))
        bot.send_message(message.chat.id,
                         'Расписание на завтра ({0}):'.format(tomorrow[:5]))
        bot.send_message(message.chat.id, display_schedule(lessons_tomorrow))
Exemplo n.º 5
0
def weekdays_delete():
    Timetable(database_url).clear_timetable()
Exemplo n.º 6
0
def parsing_timetable(date_one, date_two):
    for group_data in group_list(date_one, date_two):
        page = requests.post(schedule_url, data=group_data)
        soup = BeautifulSoup(page.text, 'html.parser')

        schedule_table = soup.find("table", {"id": "timeTableGroup"})

        header_list = [div.text for div in soup.find_all('option', selected=True)]
        print(header_list)
        lessons_data = [div.text.replace('\r', '').replace('\n', '').replace('    ', ' ')[:-1]
                        for div in schedule_table.findAll('div', attrs={"class": "cell mh-50"})][:-2]

        lessons_date = [i.text for i in schedule_table.findAll('div') if len(i.get_text()) == 10][:-2]

        lessons_order = [str(div.text[:2]) for div in schedule_table.findAll('div',
                         attrs={"class": "mh-50 cell cell-vertical"})][:-2]

        lessons_count = [div.text.count('пара') for div in schedule_table.findAll('td') if 'пара' in div.text][:-2]
        data, order = [], []

        for count in lessons_count:
            data.append(lessons_data[:count])
            order.append([int(point) for point in lessons_order[:count]])

            lessons_data = lessons_data[count:]
            lessons_order = lessons_order[count:]

        for day, k in zip(data, order):
            store = {}
            for i in range(len(day)):
                if len(day[i]) is not 0:
                    store['lesson_order'] = i+1
                    store['lesson_title'] = day[i][:day[i].index('ауд')-1]
                    day[i] = day[i][day[i].index('ауд'):]
                    store['lesson_classroom'] = ' '.join(day[i].split()[:2])
                    store['lesson_teacher'] = ' '.join(day[i].split()[2:])
                    day[i] = store
                    store = {}

        for day, date in zip(data, lessons_date):
            for lesson in day:
                if len(lesson) is not 0:
                    if header_list[0] == 'Навчально-науковий інститут заочного та дистанційного навчання':
                        header_list[0] = 'Заочне навчання'
                    lesson['faculty'] = header_list[0]
                    lesson['course'] = header_list[1]
                    lesson['group_name'] = header_list[2]
                    lesson['lesson_date'] = date

        lessons_data_db = []

        for day in data:
            for lesson in day:
                if len(lesson) is not 0:
                    lessons_data_db.append(lesson)

        timetable = Timetable(database_url)
        timetable.create_timetable()
        for _ in lessons_data_db:
            timetable.add_lesson(_['faculty'], _['course'], _['group_name'], _['lesson_date'],
                                 _['lesson_title'], _['lesson_classroom'], _['lesson_order'], _['lesson_teacher'])