diff --git a/.gitignore b/.gitignore index ee6b254..720a34b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ captcha.jpeg __pycache__/ -*.pyc \ No newline at end of file +*.pyc +/build +/dist +/sjtu_automata.egg-info \ No newline at end of file diff --git a/README.md b/README.md index b581b8b..9904225 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ -# AutoElect -![Version](https://img.shields.io/badge/Version-0.1.0-blue.svg) ![Language](https://img.shields.io/badge/Language-Python3-red.svg) ![License](https://img.shields.io/badge/License-GPL--3.0-yellow.svg) +# sjtu-automata +![Version](https://img.shields.io/badge/Version-0.1.1-blue.svg) ![Language](https://img.shields.io/badge/Language-Python3-red.svg) ![License](https://img.shields.io/badge/License-GPL--3.0-yellow.svg) **注意!此版本为BETA版,未经过严格测试,可能存在BUG,如有问题请提交[issue](https://github.com/MXWXZ/AutoElect/issues)** 上海交通大学抢课脚本\ -协议分析: +协议分析: ## 使用脚本你可以做到 :heavy_check_mark: 无人值守自动抢课\ @@ -23,9 +23,7 @@ Linux > Windows >> ~~macOS=0(没钱无测试)~~ ## 安装 - pip3 install colorama requests Pillow click pytesseract tenacity - git clone https://github.com/MXWXZ/AutoElect.git - cd AutoElect + pip3 install sjtu-automata ### [可选]验证码自动识别 Windows可以不装,Linux如无图形界面且无法通过其他方式打开`captcha.jpeg`文件需要安装。\ @@ -38,17 +36,117 @@ Ubuntu 18.04: 其他版本/发行版/Windows等自行看文档:https://github.com/tesseract-ocr/tesseract/wiki ## 简单使用说明 -**注意:经过测试网页先登录再打开软件可以同时登陆,但是任何一边提交选课后将会导致所有登陆失效。** -部分课无法选到 +**注意:经过测试网页先登录再打开软件可以同时登陆,但是任何一边提交选课后将会导致所有登陆失效。**\ +**请在海选是确认命令行参数是否正确,以免出现选课失败的情况** + +本例详细解释请看本文最后的栗子 + +海选,使用OCR,选修-个性化-ES002课程-000002老师: + + autoelect -o -r 1 -e 2/gridModule$ctl02$radioButton/ES002/000002 + +`2`为选修,`gridModule$ctl02$radioButton`为组别(个性化),`ES002`为课号,`000002`为教师号。参数获取方式见下文。 + +需要选多门课只要在后面再加上`-e xxxx`的参数就行了。 + +## 抢课说明 +- 程序运行后选课将会自动进行,如果失败自动重试,如果课程已满将自动等待并且定时刷新,直到抢成功或者用户退出为止 +- 测试版不支持多线程抢课,请等正式版稳定后再使用 +- 可以提前开上程序,如果没有开放选课将会自动等待并定时刷新,可以节省登陆的时间 +- 延时数如果调的太低会被ban30s,请酌情设置或使用默认参数 ## 参数说明 -使用:`python3 autoelect.py [-OPTIONS]` +### CLI +使用:`autoelect [OPTIONS]` |参数|长参数形式|说明| |:--:|:--:|:--:| +|-v|--version|显示版本| +|-i|--interact|交互模式(忽略其他选项)| +||--no-update|关闭更新检查| +|-r|--round|指定选课轮数(1/2/3),默认为2| +|-o|--ocr|使用OCR识别验证码| +||--print-cookie|打印登陆cookie| +||--delay-elect|人数未满检查频率(默认15s)| +||--delay-login|选课开放检查频率(默认15s)| +|-e|--elect|选课,可以使用多个,参数见下| +|-l|--list-teacher|列出教师,参数见下| +|-h|--help|显示帮助| + +选课参数:课程类型/课程组别(必修课无此项)/课号/教师ID +- 课程类型:1为必修,2为选修,3为通识,4为任选 +- 课程组别:请通过交互模式查看,必修课无组别,跳过这项即可 +- 课号:课号,如`AV001` +- 教师ID:通过交互模式或者`-l`查看 + +列出教师参数:课程类型/课程组别/课号 +- 同上 + +### 交互模式 +指定`-i`参数进入交互模式,命令说明: +|命令|参数|说明| +|:--:|:--:|:--:| +|back||返回上级,只允许在选中课号后使用| +|cd|课程类型/课程组别/课号|选中不同项目,空格分割可以连续执行| +|cookie||打印cookie| +|elect|[教师编号] [人数未满检查频率(默认15s)]|选课| +|help||显示帮助| +|login|[选课轮数] [0/1是否采用OCR] [选课开放检查频率(默认15s)]|登陆| +|ls||列出当前信息| +|quit||退出| +|update||检查更新| +|version||显示版本| + +## 栗子 + +例如下面这个选课流程,**注意//后面的内容为后期注释,实际使用不要添加!!!**\ +所有数据经过处理不包含用户信息,但是流程是一样的 + +``` +(AutoElect)> login 1 1 // 登陆,海选,使用OCR +[Warning] Only one session was permitted at the same time. Do NOT login on other browsers! +[Info] Login to your JAccount: +Username: 9S // JAccount用户名 9S +Password(no echo): // 输入你的密码,注意是没有回显的 +[Info] Login successful! +[Info] Elect round 1 is available! +(9S)$ ls // 查看必修课 + CID Name + MO001 长者语录 + MO002 动物寿命研究 + MO003 唱诗班 +(9S)$ cd 2 // 切换选修课 +(9S)$ ls // 查看选修课 + CGP Name + gridModule$ctl02$radioButton 个性化教育 +(9S)$ cd gridModule$ctl02$radioButton // 切换到个性化教育 +(9S)$ ls // 查看个性化教育 + CID Name + ES001 Steam入门 + ES002 电子竞技导论 +(9S)$ cd ES001 // 切换到ES001 +(9S ES001)$ ls // 查看老师 + TID Name + 000001 G胖 +(9S ES001)$ back // 返回(只能在查看老师后使用) +(9S)$ ls // 查看个性化教育 + CID Name + ES001 Steam入门 + ES002 电子竞技导论 +(9S)$ cd ES002 // 切换到ES002 +(9S ES002)$ ls // 查看老师 + TID Name + 000002 IG.WXZ +(9S ES002)$ elect 000002 // 选课,自动提交 +[Info] Selecting teacher...(1/2) +[Info] Submitting...(2/2) +[Info] Elect OK~ You are logged out! +[Warning] Your username and password will be remembered until you quit. +(AutoElect)> quit // 退出 +``` + +相对应的,只要确定了CGP/TID的值,即可使用下面的命令直接选课: -## 高级用法 + autoelect -o -r 1 -e 2/gridModule$ctl02$radioButton/ES002/000002 -## FAQ -1. 出现错误`Unhandled response! Retrying...`\ -一般这种情况都是教务网卡了,如果较长时间一直出现,请重新运行脚本,如果问题依旧,请提交issue。 \ No newline at end of file +其中`-o`为使用OCR,`-r 1`为海选,`-e`指定为选课模式,`2/gridModule$ctl02$radioButton/ES002/000002`就是上面我们`cd`指令执行的参数和教师编号 \ No newline at end of file diff --git a/sjtu_automata/__version__.py b/sjtu_automata/__version__.py index 8cdfec9..8d4c093 100644 --- a/sjtu_automata/__version__.py +++ b/sjtu_automata/__version__.py @@ -1,8 +1,8 @@ __title__ = 'sjtu_automata' __description__ = 'Auto elect script for SJTUer.' -__url__ = 'https://github.com/MXWXZ/sjtu_automata' -__update_url__ = 'https://raw.githubusercontent.com/MXWXZ/sjtu_automata/master/version' -__version__ = '0.1.0' +__url__ = 'https://github.com/MXWXZ/sjtu-automata' +__update_url__ = 'https://raw.githubusercontent.com/MXWXZ/sjtu-automata/master/version' +__version__ = '0.1.1' __author__ = 'MXWXZ' __author_email__ = 'me@imwxz.com' __license__ = 'GNU General Public License v3 (GPLv3)' diff --git a/sjtu_automata/autoelect.py b/sjtu_automata/autoelect.py index f9eb08b..ffc1ceb 100644 --- a/sjtu_automata/autoelect.py +++ b/sjtu_automata/autoelect.py @@ -237,7 +237,7 @@ def show_shell_help(show_error=False): echo('\n AutoElect Shell Command') echo('back back when in classid') - echo('cd [classtype/classgroup/teacherid...] change directory') + echo('cd [classtype/classgroup/classid...] change directory') echo('cookie print cookie') echo('elect [teacherid] [delay=15] elect class') echo('help show this message') @@ -411,7 +411,7 @@ def cli(interact, no_update, round, ocr, print_cookie, delay_elect, delay_login, echo('Github: '+__url__+'\n') # TODO: remove in 1.0.0 - if not (no_update or check_update()): + if not no_update and check_update(): cmd = input('Continue without updating?(y/N)') if cmd != 'y': exit() @@ -449,7 +449,8 @@ def cli(interact, no_update, round, ocr, print_cookie, delay_elect, delay_login, shell(ui, cddir) shell(ui, 'ls') else: - raise ParamError('One of -e/-l must exist!') + echoerror('One of -e/-l must exist!') + exit() if __name__ == '__main__': diff --git a/sjtu_automata/credential.py b/sjtu_automata/credential.py index 3bccfde..eb8cf88 100644 --- a/sjtu_automata/credential.py +++ b/sjtu_automata/credential.py @@ -16,7 +16,7 @@ def _create_session(): session = requests.Session() session.mount('http://', HTTPAdapter(max_retries=3)) session.mount('https://', HTTPAdapter(max_retries=3)) - session.verify = False # WARNING! Only use it in Debug mode! + # session.verify = False # WARNING! Only use it in Debug mode! return session diff --git a/version b/version index 6e8bf73..17e51c3 100644 --- a/version +++ b/version @@ -1 +1 @@ -0.1.0 +0.1.1