├── .gitignore ├── README.md ├── LICENSE └── welearn.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Object file 2 | *.o 3 | 4 | # Ada Library Information 5 | *.ali 6 | 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## **WelearnCurriculumFinsh** 2 | 1. 运行welearn.py 3 | 2. 输入账号密码或者使用cookies登录 4 | 3. 开始刷课 5 | 6 | ```shell 7 | pip install requests -i -i https://pypi.tuna.tsinghua.edu.cn/simple 8 | python3 welearn.py 9 | ``` 10 | 11 | 12 | ``` 13 | ## 特别鸣谢Avenshy和SSmJaE大佬提供的v0.1-4版本 14 | 15 | 16 | ## 简介 17 | * 输入账号密码或cookie登录并一键完成课程 18 | * 可以选择课程 19 | * 可指定每章节正确率 20 | * 已完成和未开放的章节会自动跳过 21 | 22 | ## 更新日志 23 | 24 | ` 0.5dev` 25 | 26 | * 修复了上个版本链接错误 27 | * 修复了一些逻辑错误 28 | 29 | ### `v0.4dev` 30 | * 会跳过未开放的章节了 31 | * 支持cookie登录了 32 | * 可以指定或随机正确率 33 | 34 | ### `v0.3dev` 35 | * 更pythonic(感谢SSmJaE大佬) 36 | * 支持学习指定单元了 37 | 38 | ### `v0.2dev` 39 | * 支持更多课程 40 | * 优化代码 41 | 42 | ### `v0.1dev` 43 | * 敲出首个版本的代码 44 | ``` 45 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 木兰宽松许可证, 第2版 2 | 3 | 木兰宽松许可证, 第2版 4 | 2020年1月 http://license.coscl.org.cn/MulanPSL2 5 | 6 | 7 | 您对“软件”的复制、使用、修改及分发受木兰宽松许可证,第2版(“本许可证”)的如下条款的约束: 8 | 9 | 0. 定义 10 | 11 | “软件”是指由“贡献”构成的许可在“本许可证”下的程序和相关文档的集合。 12 | 13 | “贡献”是指由任一“贡献者”许可在“本许可证”下的受版权法保护的作品。 14 | 15 | “贡献者”是指将受版权法保护的作品许可在“本许可证”下的自然人或“法人实体”。 16 | 17 | “法人实体”是指提交贡献的机构及其“关联实体”。 18 | 19 | “关联实体”是指,对“本许可证”下的行为方而言,控制、受控制或与其共同受控制的机构,此处的控制是指有受控方或共同受控方至少50%直接或间接的投票权、资金或其他有价证券。 20 | 21 | 1. 授予版权许可 22 | 23 | 每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的版权许可,您可以复制、使用、修改、分发其“贡献”,不论修改与否。 24 | 25 | 2. 授予专利许可 26 | 27 | 每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的(根据本条规定撤销除外)专利许可,供您制造、委托制造、使用、许诺销售、销售、进口其“贡献”或以其他方式转移其“贡献”。前述专利许可仅限于“贡献者”现在或将来拥有或控制的其“贡献”本身或其“贡献”与许可“贡献”时的“软件”结合而将必然会侵犯的专利权利要求,不包括对“贡献”的修改或包含“贡献”的其他结合。如果您或您的“关联实体”直接或间接地,就“软件”或其中的“贡献”对任何人发起专利侵权诉讼(包括反诉或交叉诉讼)或其他专利维权行动,指控其侵犯专利权,则“本许可证”授予您对“软件”的专利许可自您提起诉讼或发起维权行动之日终止。 28 | 29 | 3. 无商标许可 30 | 31 | “本许可证”不提供对“贡献者”的商品名称、商标、服务标志或产品名称的商标许可,但您为满足第4条规定的声明义务而必须使用除外。 32 | 33 | 4. 分发限制 34 | 35 | 您可以在任何媒介中将“软件”以源程序形式或可执行形式重新分发,不论修改与否,但您必须向接收者提供“本许可证”的副本,并保留“软件”中的版权、商标、专利及免责声明。 36 | 37 | 5. 免责声明与责任限制 38 | 39 | “软件”及其中的“贡献”在提供时不带任何明示或默示的担保。在任何情况下,“贡献者”或版权所有者不对任何人因使用“软件”或其中的“贡献”而引发的任何直接或间接损失承担责任,不论因何种原因导致或者基于何种法律理论,即使其曾被建议有此种损失的可能性。 40 | 41 | 6. 语言 42 | “本许可证”以中英文双语表述,中英文版本具有同等法律效力。如果中英文版本存在任何冲突不一致,以中文版为准。 43 | 44 | 条款结束 45 | 46 | 如何将木兰宽松许可证,第2版,应用到您的软件 47 | 48 | 如果您希望将木兰宽松许可证,第2版,应用到您的新软件,为了方便接收者查阅,建议您完成如下三步: 49 | 50 | 1, 请您补充如下声明中的空白,包括软件名、软件的首次发表年份以及您作为版权人的名字; 51 | 52 | 2, 请您在软件包的一级目录下创建以“LICENSE”为名的文件,将整个许可证文本放入该文件中; 53 | 54 | 3, 请将如下声明文本放入每个源文件的头部注释中。 55 | 56 | Copyright (c) [Year] [name of copyright holder] 57 | [Software Name] is licensed under Mulan PSL v2. 58 | You can use this software according to the terms and conditions of the Mulan PSL v2. 59 | You may obtain a copy of Mulan PSL v2 at: 60 | http://license.coscl.org.cn/MulanPSL2 61 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 62 | See the Mulan PSL v2 for more details. 63 | 64 | 65 | Mulan Permissive Software License,Version 2 66 | 67 | Mulan Permissive Software License,Version 2 (Mulan PSL v2) 68 | January 2020 http://license.coscl.org.cn/MulanPSL2 69 | 70 | Your reproduction, use, modification and distribution of the Software shall be subject to Mulan PSL v2 (this License) with the following terms and conditions: 71 | 72 | 0. Definition 73 | 74 | Software means the program and related documents which are licensed under this License and comprise all Contribution(s). 75 | 76 | Contribution means the copyrightable work licensed by a particular Contributor under this License. 77 | 78 | Contributor means the Individual or Legal Entity who licenses its copyrightable work under this License. 79 | 80 | Legal Entity means the entity making a Contribution and all its Affiliates. 81 | 82 | Affiliates means entities that control, are controlled by, or are under common control with the acting entity under this License, ‘control’ means direct or indirect ownership of at least fifty percent (50%) of the voting power, capital or other securities of controlled or commonly controlled entity. 83 | 84 | 1. Grant of Copyright License 85 | 86 | Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable copyright license to reproduce, use, modify, or distribute its Contribution, with modification or not. 87 | 88 | 2. Grant of Patent License 89 | 90 | Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable (except for revocation under this Section) patent license to make, have made, use, offer for sale, sell, import or otherwise transfer its Contribution, where such patent license is only limited to the patent claims owned or controlled by such Contributor now or in future which will be necessarily infringed by its Contribution alone, or by combination of the Contribution with the Software to which the Contribution was contributed. The patent license shall not apply to any modification of the Contribution, and any other combination which includes the Contribution. If you or your Affiliates directly or indirectly institute patent litigation (including a cross claim or counterclaim in a litigation) or other patent enforcement activities against any individual or entity by alleging that the Software or any Contribution in it infringes patents, then any patent license granted to you under this License for the Software shall terminate as of the date such litigation or activity is filed or taken. 91 | 92 | 3. No Trademark License 93 | 94 | No trademark license is granted to use the trade names, trademarks, service marks, or product names of Contributor, except as required to fulfill notice requirements in Section 4. 95 | 96 | 4. Distribution Restriction 97 | 98 | You may distribute the Software in any medium with or without modification, whether in source or executable forms, provided that you provide recipients with a copy of this License and retain copyright, patent, trademark and disclaimer statements in the Software. 99 | 100 | 5. Disclaimer of Warranty and Limitation of Liability 101 | 102 | THE SOFTWARE AND CONTRIBUTION IN IT ARE PROVIDED WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED. IN NO EVENT SHALL ANY CONTRIBUTOR OR COPYRIGHT HOLDER BE LIABLE TO YOU FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO ANY DIRECT, OR INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING FROM YOUR USE OR INABILITY TO USE THE SOFTWARE OR THE CONTRIBUTION IN IT, NO MATTER HOW IT’S CAUSED OR BASED ON WHICH LEGAL THEORY, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 103 | 104 | 6. Language 105 | 106 | THIS LICENSE IS WRITTEN IN BOTH CHINESE AND ENGLISH, AND THE CHINESE VERSION AND ENGLISH VERSION SHALL HAVE THE SAME LEGAL EFFECT. IN THE CASE OF DIVERGENCE BETWEEN THE CHINESE AND ENGLISH VERSIONS, THE CHINESE VERSION SHALL PREVAIL. 107 | 108 | END OF THE TERMS AND CONDITIONS 109 | 110 | How to Apply the Mulan Permissive Software License,Version 2 (Mulan PSL v2) to Your Software 111 | 112 | To apply the Mulan PSL v2 to your work, for easy identification by recipients, you are suggested to complete following three steps: 113 | 114 | i Fill in the blanks in following statement, including insert your software name, the year of the first publication of your software, and your name identified as the copyright owner; 115 | 116 | ii Create a file named “LICENSE” which contains the whole context of this License in the first directory of your software package; 117 | 118 | iii Attach the statement to the appropriate annotated syntax at the beginning of each source file. 119 | 120 | 121 | Copyright (c) [Year] [name of copyright holder] 122 | [Software Name] is licensed under Mulan PSL v2. 123 | You can use this software according to the terms and conditions of the Mulan PSL v2. 124 | You may obtain a copy of Mulan PSL v2 at: 125 | http://license.coscl.org.cn/MulanPSL2 126 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 127 | See the Mulan PSL v2 for more details. 128 | -------------------------------------------------------------------------------- /welearn.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import re 3 | import sys 4 | from sys import argv 5 | from time import sleep 6 | from random import randint 7 | session = requests.Session() 8 | # print("********** 特别鸣谢 Avenshy & SSmJaE **********") 9 | # print(" Version:0.5dev\n") 10 | # print("********** 此版本更新于Hhy **********") 11 | # print("***************************************************\n") 12 | 13 | 14 | 15 | def printline(): 16 | print('-'*51) 17 | 18 | 19 | # 获取账户密码 20 | try: # 直接从命令行中获取 21 | username, password = sys.argv[1], sys.argv[2] 22 | except: 23 | loginmode = input('请选择登录方式: \n 1.账号密码登录\n 2.Cookie登录\n\n请输入数字1或2: ') 24 | printline() 25 | if loginmode == '1': 26 | username = input('请输入账号: ') 27 | password = input('请输入密码: ') 28 | # 登录模块 29 | response = requests.get( 30 | 'https://welearn.sflep.com/user/prelogin.aspx?loginret=http%3a%2f%2fwelearn.sflep.com%2fuser%2floginredirect.aspx', allow_redirects=False) 31 | rturl = response.headers['Location'].replace( 32 | 'https://sso.sflep.com/idsvr', '') 33 | data = { 34 | 'rturl': rturl, 35 | 'account': username, 36 | 'pwd': password, 37 | } 38 | res = session.post( 39 | "https://sso.sflep.com/idsvr/account/login", data=data) 40 | url = 'https://sso.sflep.com/idsvr'+rturl 41 | res = session.get(url) 42 | print(res.text) 43 | if "localStorage.setItem('authToken'" in res.text: 44 | print("登录成功!!") 45 | else: 46 | input("登录失败!!") 47 | exit(0) 48 | elif loginmode == '2': 49 | try: 50 | cookie = dict(map(lambda x: x.split('=', 1), 51 | input('请粘贴Cookie: ').split(";"))) 52 | except: 53 | input('Cookie输入错误!!!') 54 | exit(0) 55 | for k, v in cookie.items(): 56 | session.cookies[k] = v 57 | else: 58 | input('输入错误!!') 59 | exit(0) 60 | printline() 61 | while True: 62 | # 查询课程信息 63 | url = "https://welearn.sflep.com/ajax/authCourse.aspx?action=gmc" 64 | response = session.get( 65 | url, headers={"Referer": "https://welearn.sflep.com/student/index.aspx"}) 66 | if '\"clist\":[]}' in response.text: 67 | input('发生错误!!!可能是登录错误或没有课程!!!') 68 | exit(0) 69 | else: 70 | print('查询课程成功!!!') 71 | printline() 72 | print('我的课程: \n') 73 | back = response.json()["clist"] 74 | for i, course in enumerate(back, start=1): 75 | print(f'[NO.{i:>2}] 完成度{course["per"]:>3}% {course["name"]}') 76 | 77 | # 选择课程 78 | order = int(input("\n请输入需要完成的课程序号(上方[]内的数字): ")) 79 | cid = back[order - 1]["cid"] 80 | printline() 81 | print("获取单元中...") 82 | printline() 83 | # 刷课模块 84 | url = f"https://welearn.sflep.com/student/course_info.aspx?cid={cid}" 85 | response = session.get(url) 86 | 87 | uid = re.search('"uid":(.*?),', response.text).group(1) 88 | classid = re.search('"classid":"(.*?)"', response.text).group(1) 89 | 90 | url = 'https://welearn.sflep.com/ajax/StudyStat.aspx' 91 | response = session.get(url, params={'action': 'courseunits', 'cid': cid, 'uid': uid}, headers={ 92 | 'Referer': 'https://welearn.sflep.com/student/course_info.aspx'}) 93 | back = response.json()['info'] 94 | 95 | # 选择单元 使用了WELearnToSleeep的代码 96 | print('[NO. 0] 按顺序完成全部单元课程') 97 | unitsnum = len(back) 98 | for i, x in enumerate(back, start=1): 99 | if x['visible'] == 'true': 100 | print(f'[NO.{i:>2d}] [已开放] {x["unitname"]} {x["name"]}') 101 | else: 102 | print(f'[NO.{i:>2d}] ![未开放]! {x["unitname"]} {x["name"]}') 103 | unitidx = int(input('\n\n请选择需要完成的单元序号(上方[]内的数字,输入0为按顺序刷全部单元): ')) 104 | printline() 105 | inputcrate = input( 106 | '模式1:每个练习指定正确率,请直接输入指定的正确率\n如:希望每个练习正确率均为100,则输入 100\n\n模式2:每个练习随机正确率,请输入正确率上下限并用英文逗号隔开\n如:希望每个练习正确率为70~100,则输入 70,100\n\n请严格按照以上格式输入每个练习的正确率: ') 107 | if ',' in inputcrate: 108 | mycrate = eval(inputcrate) 109 | randommode = True 110 | else: 111 | mycrate = inputcrate 112 | randommode = False 113 | printline() 114 | # 伪造请求 115 | way1Succeed, way2Succeed, way1Failed, way2Failed = 0, 0, 0, 0 116 | 117 | ajaxUrl = "https://welearn.sflep.com/Ajax/SCO.aspx" 118 | infoHeaders = { 119 | "Referer": f"https://welearn.sflep.com/student/course_info.aspx?cid={cid}", 120 | } 121 | 122 | if(unitidx == 0): 123 | i = 0 124 | else: 125 | i = unitidx - 1 126 | unitsnum = unitidx 127 | 128 | while True: 129 | response = session.get( 130 | f'https://welearn.sflep.com/ajax/StudyStat.aspx?action=scoLeaves&cid={cid}&uid={uid}&unitidx={i}&classid={classid}', headers=infoHeaders) 131 | 132 | if "异常" in response.text or "出错了" in response.text: 133 | break 134 | 135 | for course in response.json()["info"]: 136 | if course['isvisible'] == 'false': # 跳过未开放课程 137 | print(f'[!!跳过!!] {course["location"]}') 138 | elif "未" in course["iscomplete"]: # 章节未完成 139 | print(f'[即将完成] {course["location"]}') 140 | if randommode is True: 141 | crate = str(randint(mycrate[0], mycrate[1])) 142 | else: 143 | crate = mycrate 144 | data = '{"cmi":{"completion_status":"completed","interactions":[],"launch_data":"","progress_measure":"1","score":{"scaled":"'+crate + \ 145 | '","raw":"100"},"session_time":"0","success_status":"unknown","total_time":"0","mode":"normal"},"adl":{"data":[]},"cci":{"data":[],"service":{"dictionary":{"headword":"","short_cuts":""},"new_words":[],"notes":[],"writing_marking":[],"record":{"files":[]},"play":{"offline_media_id":"9999"}},"retry_count":"0","submit_time":""}}[INTERACTIONINFO]' 146 | 147 | id = course["id"] 148 | session.post(ajaxUrl, data={"action": "startsco160928", 149 | "cid": cid, 150 | "scoid": id, 151 | "uid": uid 152 | }, 153 | headers={"Referer": f"https://welearn.sflep.com/Student/StudyCourse.aspx?cid={cid}&classid={classid}&sco={id}"}) 154 | response = session.post(ajaxUrl, data={"action": "setscoinfo", 155 | "cid": cid, 156 | "scoid": id, 157 | "uid": uid, 158 | "data": data, 159 | "isend": "False"}, 160 | headers={"Referer": f"https://welearn.sflep.com/Student/StudyCourse.aspx?cid={cid}&classid={classid}&sco={id}"}) 161 | print(f'>>>>>>>>>>>>>>正确率:{crate:>3}%', end=' ') 162 | if '"ret":0' in response.text: 163 | print("方式1:成功!!!", end=" ") 164 | way1Succeed += 1 165 | else: 166 | print("方式1:失败!!!", end=" ") 167 | way1Failed += 1 168 | 169 | response = session.post(ajaxUrl, data={"action": "savescoinfo160928", 170 | "cid": cid, 171 | "scoid": id, 172 | "uid": uid, 173 | "progress": "100", 174 | "crate": crate, 175 | "status": "unknown", 176 | "cstatus": "completed", 177 | "trycount": "0", 178 | }, 179 | headers={"Referer": f"https://welearn.sflep.com/Student/StudyCourse.aspx?cid={cid}&classid={classid}&sco={id}"}) 180 | # sleep(1) # 延迟1秒防止服务器压力过大 181 | if '"ret":0' in response.text: 182 | print("方式2:成功!!!") 183 | way2Succeed += 1 184 | else: 185 | print("方式2:失败!!!") 186 | way2Failed += 1 187 | else: # 章节已完成 188 | print(f'[ 已完成 ] {course["location"]}') 189 | 190 | if unitidx != 0: 191 | break 192 | else: 193 | i += 1 194 | if unitidx == 0: 195 | break 196 | else: 197 | print('本单元运行完毕!回到选课处!!\n\n\n\n') 198 | printline() 199 | 200 | printline() 201 | print(f""" 202 | *************************************************** 203 | 全部完成!! 204 | 205 | 总计: 206 | 方式1: {way1Succeed} 成功, {way1Failed} 失败 207 | 方式2: {way2Succeed} 成功, {way2Failed} 失败 208 | 209 | ********** 有问题请邮件联系hhy5562877@163.com **********""") 210 | input("按任意键退出") 211 | --------------------------------------------------------------------------------