Exemple #1
0
def notifying_lectures_process(bot):
    print('Starting to notify about upcoming lectures..')
    while True:
        if time_helpers.current_time_in_minutes(
        ) >= 120 and time_helpers.current_time_in_minutes() <= 420:
            continue
        chats = api_calls.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)
Exemple #2
0
def notify_users(bot):
    chats = api_calls.get_all_chats_info()
    for chat in chats:
        chat_id = chat['chat_id']
        send_message(
            bot,
            chat_id=chat_id,
            text=
            'Дорогие девушки, поздравляем вас с этим замечательным днем! Будьте счастливы и оставайтесь всегда такими же красивыми 😍'
        )
    print('Done!')
Exemple #3
0
def notifying_webworks_process(bot):
    while True:
        print('Starting to notify about new webworks..')
        chats = api_calls.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:
                    print('Webworks exception occured but still running..')
                    pass
        time.sleep(14400)
Exemple #4
0
def get_girls():
    girls = []
    with requests.Session() as s:
        p = s.get(url=START_URL, params=PARAMS)
        chats = api_calls.get_all_chats_info()
        for chat in chats:
            if not 'username' in chat:
                continue
            username = chat['username']
            chat_id = chat['chat_id']
            result = get_name(username, s, p.cookies)
            if len(result) > 0:
                girls.append((result, chat_id))
                print('{} - {}'.format(girls[-1][0], girls[-1][1]))
    return girls
Exemple #5
0
def notifying_grades_process(bot):
    rep = 0
    while True:
        if time_helpers.current_time_in_minutes(
        ) >= 120 and time_helpers.current_time_in_minutes() <= 420:
            continue
        rep += 1
        print('Starting to check for new grades.. {}'.format(rep))
        chats = api_calls.get_all_chats_info()
        total_number = len(chats)
        current_number = 0
        for chat in chats:
            current_number += 1
            if not 'notify_grades' in chat or not chat['notify_grades']:
                continue
            try:
                chat_id = chat['chat_id']
                username = chat['username']
                main_password = chat['main_password']
                print('Checking {} grades.. {}/{}'.format(
                    username, current_number, total_number))
                current_grades = moodle_login.get_grades(
                    username, main_password)
                if len(current_grades.keys()) == 0:
                    send_message(bot,
                                 chat_id=chat_id,
                                 text=bot_messages.password_changed_response)
                    api_calls.disable_notify_grades_for_chat(chat_id)
                    continue
                old_grades = chat['grades']
                for course_name, course_grades in current_grades.items():
                    if not course_name in old_grades:
                        old_grades[course_name] = []
                    for course_grade in course_grades:
                        name = course_grade['name']
                        grade = course_grade['grade']
                        unique_grade = True
                        for old_grade in old_grades[course_name]:
                            old_name = old_grade['name']
                            old_grade = old_grade['grade']
                            if old_name == name and old_grade == grade:
                                unique_grade = False
                        if unique_grade and course_name.lower(
                        ) != 'error' and name.lower(
                        ) != 'error' and grade.lower() != 'error':
                            send_message(bot,
                                         chat_id=chat_id,
                                         text='Новая оценка!\n\n')
                            info = '{} - <b>{}</b>\n'.format(
                                'Course name', course_name)
                            info += '{} - <b>{}</b>\n'.format(
                                'Grade name', name)
                            info += '{} - <b>{}</b>\n'.format('Grade', grade)
                            if 'range' in course_grade and course_grade[
                                    'range'].lower() != 'error':
                                info += '{} - <b>{}</b>\n'.format(
                                    'Range', course_grade['range'])
                            if 'percentage' in course_grade and course_grade[
                                    'percentage'].lower() != 'error':
                                info += '{} - <b>{}</b>\n'.format(
                                    'Percentage', course_grade['percentage'])
                            send_message(bot, chat_id=chat_id, text=info)
                            print('{} got a new grade'.format(username))
                            print('{} - {} - {}'.format(
                                course_name, name, grade))
                set_grades_for_chat(chat_id, current_grades)
            except:
                print('Grades exception occured but still running..')
                pass
Exemple #6
0
def get_all_chats_info():
    try:
        return api_calls.get_all_chats_info()
    except:
        restart_heroku_dynos()
        pass