async def grade(session: CommandSession): exam_state = get_exam_state(str(session.ctx['user_id'])) if exam_state != 0: await session.send('此功能仍在测试状态,可能出现各种bug,如果遭遇bug请使用“反馈”指令通知管理员') accentlist = chmod.read_chmod() if accentlist[str(session.ctx['user_id'])] != '?': if str(session.ctx['user_id']) in accentlist: accent = accentlist[str(session.ctx['user_id'])] password = session.get('password', prompt='请输入密 码') await session.send('请稍后,正在尝试连接教务系统') cookie = login(accent, password, session) if cookie == 1: await session.send('验证码识别错误,请重试') elif cookie == 0: await session.send('密码错误,请重试') elif cookie == 2: await session.send('账号不存在,请尝试重新绑定账号') else: time.sleep(1) result = get_grade(cookie) for coursein in result: await session.send(coursein[:-1]) else: await session.send('清先绑定账号') else: await session.send('您的账号权限不足')
async def examn(session: CommandSession): exam_state = get_exam_state(str(session.ctx['user_id'])) if exam_state != 0: accentlist = chmod.read_chmod() if accentlist[str(session.ctx['user_id'])] != '?': if str(session.ctx['user_id']) in accentlist: accent = accentlist[str(session.ctx['user_id'])] password = session.get('password', prompt='请输入密 码') await session.send('请稍后,正在尝试连接教务系统') cookie = login(accent, password, session) if cookie == 1: await session.send('验证码识别错误,请重试') elif cookie == 0: await session.send('密码错误,请重试') elif cookie == 2: await session.send('账号不存在,请尝试重新绑定账号') else: time.sleep(1) exam = get_exam(cookie) i = 0 text = '' for project in exam: if project != '': if i == 0: text += '课程编号:' + project + '\n' elif i == 1: text += '课程名称:' + project + '\n' elif i == 2: text += '考试类型:' + project + '\n' elif i == 3: text += '考试日期:' + project + '\n' elif i == 4: text += '考试时间:' + project + '\n' elif i == 5: text += '考试地点:' + project + '\n' elif i == 6: text += '考试座位:' + project + '\n' elif i == 7: text += '考试状态:' + project + '\n' i = i + 1 else: i = 0 text = text.replace('<fontcolor="BBC4C3">', '') text = text.replace('</font>', '') await session.send(text[:-1]) text = '' else: await session.send('清先绑定账号') else: await session.send('您的账号权限不足')
async def course_cal(session: CommandSession): exam_state = get_exam_state(str(session.ctx['user_id'])) if exam_state != 0: accentlist = chmod.read_chmod() http_path = read('server', 'http_path') address = read('server', 'address') if str(session.ctx['user_id']) in accentlist: if accentlist[str(session.ctx['user_id'])] != '?': accent = accentlist[str(session.ctx['user_id'])] password = session.get('password', prompt='请输入密 码') await session.send('请稍后,正在尝试连接教务系统') cookie = login(accent, password, session) if cookie == 1: await session.send('验证码识别错误,请重试') elif cookie == 0: await session.send('密码错误,请重试') elif cookie == 2: await session.send('账号不存在,请尝试重新绑定账号') else: time.sleep(1) table = get_course(cookie, '') lessons = parseCourseTable(table) semester_start_date = datetime( 2019, 9, 2, 0, 0, 0, tzinfo=timezone('Asia/Shanghai')) cal = create_ics(lessons, semester_start_date) export_ics(cal, str(session.ctx['user_id'])) filename = 'NUAAiCal-Data/' + str( session.ctx['user_id']) + '.ics' shutil.copyfile( os.path.abspath(filename), http_path + str(session.ctx['user_id']) + '.ics') await session.send('点击网址下载日历文件 http://' + address + '/' + str(session.ctx['user_id']) + '.ics') await session.send( '本日历模块来自miaotony的github开源项目,感谢他对开源社区做出的贡献') else: await session.send('清先绑定账号') else: await session.send('您的账号权限不足')
async def course(session: CommandSession): exam_state = get_exam_state(str(session.ctx['user_id'])) if exam_state != 0: accentlist = chmod.read_chmod() http_path = read('server', 'http_path') address = read('server', 'address') if str(session.ctx['user_id']) in accentlist: if accentlist[str(session.ctx['user_id'])] != '?': accent = accentlist[str(session.ctx['user_id'])] password = session.get('password', prompt='请输入密 码') await session.send('请稍后,正在尝试连接教务系统') cookie = login(accent, password, session) if cookie == 1: await session.send('验证码识别错误,请重试') elif cookie == 0: await session.send('密码错误,请重试') elif cookie == 2: await session.send('账号不存在,请尝试重新绑定账号') else: time.sleep(1) week = get_week(cookie) table = get_course(cookie, week) table = table.replace('/eams', 'http://aao-eas.nuaa.edu.cn/eams') with open(http_path + str(session.ctx['user_id']) + '.html', 'w', encoding='utf-8') as f: f.write(table) f.close() await session.send('点击网址查看课程表 http://' + address + '/' + str(session.ctx['user_id']) + '.html') else: await session.send('清先绑定账号') else: await session.send('您的账号权限不足')
async def exam(session: CommandSession): exam_state = get_exam_state(str(session.ctx['user_id'])) if exam_state != 0: accentlist = chmod.read_chmod() if accentlist[str(session.ctx['user_id'])] != '?': if str(session.ctx['user_id']) in accentlist: accent = accentlist[str(session.ctx['user_id'])] password = session.get('password', prompt='请输入密 码') await session.send('请稍后,正在尝试连接教务系统') cookie = login(accent, password, session) if cookie == 1: await session.send('验证码识别错误,请重试') elif cookie == 0: await session.send('密码错误,请重试') elif cookie == 2: await session.send('账号不存在,请尝试重新绑定账号') else: time.sleep(1) exam = get_exam(cookie) i = 0 flag = 0 text = '' timet = '' for project in exam: if project != '': if i == 0: text += '课程编号:' + project + '\n' elif i == 1: text += '课程名称:' + project + '\n' elif i == 2: text += '考试类型:' + project + '\n' elif i == 3: text += '考试日期:' + project + '\n' if project.find('未安排', 0, len(project)) == -1: timet += project + ' ' elif i == 4: text += '考试时间:' + project + '\n' if project.find('未安排', 0, len(project)) == -1: timet += project.split('~')[1] + ':00' elif i == 5: text += '考试地点:' + project + '\n' elif i == 6: text += '考试座位:' + project + '\n' elif i == 7: text += '考试状态:' + project + '\n' i = i + 1 else: i = 0 text = text.replace('<fontcolor="BBC4C3">', '') text = text.replace('</font>', '') if timet == '': await session.send(text[:-1]) else: timet = time.mktime( time.strptime(timet, "%Y-%m-%d %H:%M:%S")) timen = time.time() if timen <= timet: await session.send(text[:-1]) else: flag = 1 text = '' timet = '' if flag == 1: await session.send('有部分过去的考试被隐藏,若需查看请使用“查询全部考试”指令查询') else: await session.send('清先绑定账号') else: await session.send('您的账号权限不足')