示例#1
0
文件: main.py 项目: Akezh/indigo
def get_schedule(bot, update):
    chat_info = api_calls.get_chat_info(update.message.chat_id)
    if not 'main_password' in chat_info or not 'username' in chat_info:
        update.message.reply_text(bot_messages.no_login_or_password_response)
    else:
        send_message(bot,
                     chat_id=update.message.chat_id,
                     text=bot_messages.checking_data_response)
        try:
            schedule = registrar_login.get_schedule(chat_info['username'],
                                                    chat_info['main_password'])
            print('{} used /get_schedule command'.format(
                chat_info['username']))
            if len(schedule.keys()) == 0:
                send_message(bot,
                             chat_id=update.message.chat_id,
                             text=bot_messages.wrong_registrar_data_response)
            else:
                send_message(
                    bot,
                    chat_id=update.message.chat_id,
                    text=bot_messages.successful_registrar_login_response)
                api_calls.update_schedule_for_chat(update.message.chat_id,
                                                   schedule)
        except:
            print('Schedule error....')
示例#2
0
文件: main.py 项目: KtlTheBest/indigo
def notify_webwork(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 'webwork_password' in chat_info or not 'username' in chat_info:
        update.message.reply_text(
            bot_messages.no_webwork_login_or_password_response,
            parse_mode='HTML')
    else:
        send_message(bot,
                     chat_id=chat_id,
                     text=bot_messages.checking_data_response)
        current_webworks = webwork_login.get_webworks(
            chat_info['username'], chat_info['webwork_password'])
        if len(current_webworks.keys()) == 0:
            send_message(bot,
                         chat_id=chat_id,
                         text=bot_messages.wrong_webwork_data_response)
        else:
            send_message(bot,
                         chat_id=chat_id,
                         text=bot_messages.successful_webwork_login_response)
            for section, webworks in current_webworks.items():
                for webwork in webworks:
                    send_message(bot,
                                 chat_id=chat_id,
                                 text='• {} - {}'.format(section, webwork))
            set_webworks_for_chat(chat_id, current_webworks)
示例#3
0
文件: main.py 项目: KtlTheBest/indigo
def check_new_webworks(bot, chat_id):
    chat_info = api_calls.get_chat_info(chat_id)
    username = chat_info['username']
    password = chat_info['webwork_password']
    old_webworks = chat_info['webworks']
    current_webworks = webwork_login.get_webworks(username, password)
    if len(current_webworks.keys()) == 0:
        return
    for course_name, webworks in current_webworks.items():
        for new_webwork in webworks:
            if (not course_name in old_webworks) or (
                    not new_webwork in old_webworks[course_name]):
                notify_about_new_webwork(bot, chat_id, course_name,
                                         new_webwork)
    if 'INDIGO_PROD' in os.environ:
        set_webworks_for_chat(chat_id, current_webworks)
示例#4
0
文件: main.py 项目: Akezh/indigo
def notify_grades(bot, update):
    chat_info = api_calls.get_chat_info(update.message.chat_id)
    if not 'main_password' in chat_info or not 'username' in chat_info:
        update.message.reply_text(bot_messages.no_login_or_password_response)
    else:
        send_message(bot,
                     chat_id=update.message.chat_id,
                     text=bot_messages.checking_data_response)
        current_grades = moodle_login.get_grades(chat_info['username'],
                                                 chat_info['main_password'])
        if len(current_grades.keys()) == 0:
            send_message(bot,
                         chat_id=update.message.chat_id,
                         text=bot_messages.wrong_registrar_data_response)
        else:
            send_message(bot,
                         chat_id=update.message.chat_id,
                         text=bot_messages.successful_moodle_login_response)
            set_grades_for_chat(update.message.chat_id, current_grades)
示例#5
0
文件: main.py 项目: Akezh/indigo
def show_schedule(bot, update):
    update.message.reply_text(bot_messages.wait_please_response)
    chat_id = update.message.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:
        print('{} used /show_schedule command'.format(chat_info['username']))
        schedule = chat_info['schedule']
        message = ''
        for day, subjects in schedule.items():
            message = message + '<b>{}</b>\n\n'.format(day)
            if len(subjects) == 0:
                message = message + bot_messages.no_lectures_this_day
            for subject in subjects:
                message = message + '{}\n{} - {}\n{}\n'.format(
                    subject['course_name'], subject['start_time'],
                    subject['end_time'], subject['lecture_room'])
                message = message + '\n'
        send_message(bot, chat_id=chat_id, text=message)
示例#6
0
文件: main.py 项目: KtlTheBest/indigo
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