├── .gitignore ├── LICENSE ├── README.md └── SSA.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2022 Doone 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SSA 2 | **学习通座位签到、预约、退座、暂离、综合信息查询(包含座位楼层位置、所有座位的使用信息、签到地理位置范围等)** 3 | 4 | > 具体用法请看注释,日后有时间更新详细。 5 | 6 | # 目前已知问题 7 | 8 | > **不同学校的数据格式有些许的不同,可以在issues提交你的问题,我会尽力解决的。** 9 | 10 | ## 苹果捷径简单教程 11 | 12 | * 从url获取内容,url填上你要请求的地址,请求方式选择post,添加两个文本值,详细看下方的请求参数。 13 | * 获取字典值,获取"msg"的值 14 | * 显示提醒,将msg的值显示在弹窗。 15 | 16 | ## 接口更新日志(注意:它只支持最新一期的图书馆预约系统2021年,如果你的学校不适用,请将所有请求的域名中的seat修改为seatengine并附带seatId的值再试或者提交issues) 17 | 18 | ### 2022年3月8日21:25:43 19 | 20 | * 修复了在多预约的情况下签到失败的问题,现在将之间签到最近待签到的座位。 21 | * 不久后更新老版系统的签到、退座、取消和暂离。 22 | * 不久后开放**预约接口**。 23 | 24 | ### 2022年3月6日20:40:45 25 | 26 | * 修复了在多预约情况下不能签到的问题。 27 | * 修复了正在学习的座位取消导致上限的问题(建议退座,这样不消耗预约次数。) 28 | * 优化了返回的信息提示,更加人性化啦。 29 | 30 | ### 2022年3月5日13:17:01 31 | 32 | * 修复了请求返回时显示手机号或者密码的错误提示,但实际已操作。 33 | * 优化了文字提示:成功操作会显示位置已经座位号。 34 | 35 | ## 部分功能已经开通接口(支持苹果捷径!) 36 | 37 | ### 签到 38 | 39 | ``` python 40 | # 请求地址:https://o.nvidia.fun:12345/sign 41 | # 请求方法:post 42 | # 请求参数: 43 | { 44 | "phonenums": "手机号", 45 | "key":"密码" 46 | } 47 | 48 | # response 49 | { 50 | "msg": "不在签到时间内无法签到", 51 | "value": "True" 52 | } 53 | ``` 54 | 55 | ### 离开、退座和取消 56 | 57 | * 使用方法与签到一致,离开、退座和取消分别把url上的"sign"替换成"leave"、"signback"和"cancel"即可~ 58 | -------------------------------------------------------------------------------- /SSA.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3.7.0 2 | # -*- coding: utf-8 -*- 3 | import requests 4 | import base64 5 | import re 6 | import time 7 | from lxml import etree 8 | import threading 9 | import queue 10 | 11 | 12 | class CX: 13 | # 实例化请传入手机号和密码 14 | def __init__(self, phonenums, password): 15 | self.acc = phonenums 16 | self.pwd = password 17 | self.mappid = None 18 | self.incode = None 19 | self.deptIdEnc = None 20 | self.room = None 21 | self.deptId = None 22 | self.room_id_name = {} 23 | self.room_id_capacity = {} 24 | self.all_seat = [] 25 | self.db = { 26 | 'sb': 0, 27 | 'nb': 0 28 | } 29 | self.session = requests.session() 30 | self.session.headers = { 31 | 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 ' 32 | '(KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1', 33 | } 34 | self.login() # 第一步 必须 35 | self.status = { 36 | '0': '待履约', 37 | '1': '学习中', 38 | '2': '已履约', 39 | '3': '暂离中', 40 | '5': '被监督中', 41 | '7': '已取消', 42 | } 43 | self.get_fidEnc() # 第二步 必须 44 | self.get_all_room_and_seat() # 这一步看需求 非必须 45 | 46 | # 获取cookies 47 | def login(self): 48 | c_url = 'https://passport2.chaoxing.com/mlogin?' \ 49 | 'loginType=1&' \ 50 | 'newversion=true&fid=&' \ 51 | 'refer=http%3A%2F%2Foffice.chaoxing.com%2Ffront%2Fthird%2Fapps%2Fseat%2Findex' 52 | self.session.get(c_url).cookies.get_dict() 53 | data = { 54 | 'fid': '-1', 55 | 'uname': self.acc, 56 | 'password': base64.b64encode(self.pwd.encode()).decode(), 57 | 'refer': 'http%3A%2F%2Foffice.chaoxing.com%2Ffront%2Fthird%2Fapps%2Fseat%2Findex', 58 | 't': 'true' 59 | } 60 | self.session.post('https://passport2.chaoxing.com/fanyalogin', data=data) 61 | s_url = 'https://office.chaoxing.com/front/third/apps/seat/index' 62 | self.session.get(s_url) 63 | 64 | # 身份获取 官方的接口 自行研究 65 | def get_role(self): 66 | role = self.session.get(url='https://office.chaoxing.com/data/apps/seat/person/role').json() 67 | # print(role) 68 | try: 69 | for index in role['data']['roleList']['data']: 70 | if role['data']['roleListSelf'][0]['roleId'] == index['roleid']: 71 | myRole = index['roleName'] # 身份 72 | print(myRole) 73 | break 74 | except KeyError: 75 | print('服务器未响应正确值,请重试') 76 | 77 | # 其他的无关信息 78 | def get_wx(self): 79 | reserve_wx_config = self.session.post(url='https://office.chaoxing.com/data/apps/reserve/wx/config').json() 80 | seatIndex = self.session.get(url='https://office.chaoxing.com/data/apps/seat/index').json() 81 | seatConfig = self.session.get(url='https://office.chaoxing.com/data/apps/seat/config').json() 82 | # print(reserve_wx_config) 83 | # print(seatIndex) 84 | # print(seatConfig) 85 | 86 | # 获取学校id 87 | def get_fidEnc(self): 88 | data = { 89 | 'searchName': '', 90 | '_t': self.get_date() 91 | } 92 | res = self.session.post(url='https://i.chaoxing.com/base/cacheUserOrg', data=data) 93 | print(res.json()["site"][0]['schoolname'], res.json()["site"][1]['schoolname']) # 默认显示单位的前两个名称如果是多个单位请自行修改 94 | for index in res.json()["site"]: 95 | fid = index['fid'] 96 | res = self.session.get(url='https://uc.chaoxing.com/mobileSet/homePage?' 97 | f'fid={fid}') 98 | selector = etree.HTML(res.text) 99 | mappid = selector.xpath('/html/body/div[1]/div[3]/ul/li[1]/@onclick') # ☆ 注意 这一步可能需要调整 否则不能正常获取到mappid 每个学校不一样此处就没有用RE ☆ 100 | if mappid: 101 | self.mappid = mappid[0].split('(')[1].split(',')[0] 102 | self.incode = self.session.cookies.get_dict()['wfwIncode'] 103 | url = f'https://v1.chaoxing.com/mobile/openRecentApp?incode={self.incode}&mappId={self.mappid}' 104 | res = self.session.get(url=url, allow_redirects=False) 105 | # 每个学校的deptIdEnc值是固定的,如果是为只为你的学校提供服务请直接将deptIdEnc保存!不需要再执行get_fidEnc()方法了 106 | self.deptIdEnc = re.compile("fidEnc%3D(.*?)%").findall(res.headers['Location'])[0] 107 | 108 | # 获全部预约记录 109 | def get_seat_reservation_info(self): 110 | # 注意 老版本的系统需要将url中的seat改为seatengine 111 | response = self.session.get(url='https://office.chaoxing.com/data/apps/seat/reservelist?' 112 | 'indexId=0&' 113 | 'pageSize=100&' 114 | 'type=-1').json()['data']['reserveList'] 115 | print(response) 116 | for index in response: 117 | if index['type'] == -1: 118 | print(index['seatNum'], index['id'], index['firstLevelName'], index['secondLevelName'], 119 | index['thirdLevelName'], self.t_time(index['startTime']), self.t_time(index['endTime']), 120 | self.t_second(index['learnDuration']), self.status[str(index['status'])]) 121 | else: 122 | print(index['seatNum'], index['id'], index['firstLevelName'], index['secondLevelName'], 123 | index['thirdLevelName'], self.t_time(index['startTime']), self.t_time(index['endTime']), 124 | self.t_second(index['learnDuration']), '违约') 125 | 126 | # 签到 127 | def sign(self): 128 | # 注意 老版本的系统需要将url中的seat改为seatengine 129 | response = self.session.get(url='https://office.chaoxing.com/data/apps/seat/sign?' 130 | f'id={self.get_my_seat_id()}') 131 | print(response.json()) 132 | 133 | # 暂离 134 | def leave(self): 135 | # 注意 老版本的系统需要将url中的seat改为seatengine 136 | response = self.session.get(url='https://office.chaoxing.com/data/apps/seat/leave?' 137 | f'id={self.get_my_seat_id()}') 138 | print(response.json()) 139 | 140 | # 退座 141 | def signback(self): 142 | # 注意 老版本的系统需要将url中的seat改为seatengine 143 | response = self.session.get(url='https://office.chaoxing.com/data/apps/seat/signback?' 144 | f'id={self.get_my_seat_id()}') 145 | print(response.json()) 146 | 147 | # 取消 148 | def cancel(self): 149 | # 注意 老版本的系统需要将url中的seat改为seatengine 150 | response = self.session.get(url='https://office.chaoxing.com/data/apps/seat/cancel?' 151 | f'id={self.get_my_seat_id()}') 152 | print(response.json()) 153 | 154 | # 时间戳转换1 155 | @classmethod 156 | def t_time(cls, timestamp): 157 | return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(str(timestamp)[0:10]))) 158 | 159 | # 时间戳转换2 160 | @classmethod 161 | def t_second(cls, timestamp): 162 | if timestamp: 163 | m, s = divmod(int(str(timestamp)[0:-3]), 60) 164 | h, m = divmod(m, 60) 165 | if m: 166 | if h: 167 | return str(h) + "时" + str(m) + "分" + str(s) + "秒" 168 | return str(m) + "分" + str(s) + "秒" 169 | return str(s) + "秒" 170 | return "0秒" 171 | 172 | # 预约座位 需要自己修改 173 | def submit(self): 174 | # 注意 老版本的系统需要将url中的seat改为seatengine且不需要第一步获取list。有可能需要提供seatId的值 175 | # 获取token 176 | response = self.session.get(url='https://office.chaoxing.com/front/apps/seat/list?' 177 | f'deptIdEnc={self.deptIdEnc}') 178 | pageToken = re.compile(r"&pageToken=' \+ '(.*)' \+ '&").findall(response.text)[0] 179 | # print(pageToken) 180 | response = self.session.get(url='https://office.chaoxing.com/front/apps/seat/select?' 181 | 'id=6296&' # 房间id roomId 可以从self.room_id_name获取 请自行发挥 182 | 'day=2022-03-01&' # 预约时间 上下需保持一致 183 | 'backLevel=2&' # 必须的参数2 184 | f'pageToken={pageToken}') 185 | token = re.compile("token: '(.*)'").findall(response.text)[0] 186 | # print(token) 187 | response = self.session.get(url='https://office.chaoxing.com/data/apps/seat/submit?' 188 | 'roomId=6296&' # 房间id roomId 上下需保持一致 189 | 'startTime=9%3A00&' # 开始时间%3A代表: 自行替换9(小时)和后面00(分钟) 必须 190 | 'endTime=11%3A00&' # 结束时间 规则同上 191 | 'day=2022-03-01&' # 预约时间 上下需保持一致 192 | 'seatNum=148&' # 座位数字 与桌上贴纸一致 193 | f'token={token}') 194 | seat_result = response.json() 195 | print(seat_result) 196 | 197 | # 标准时间转换 198 | @classmethod 199 | def get_date(cls): 200 | return time.strftime('%a %b %d %Y %I:%M:%S GMT+0800 ', time.localtime(time.time())) + '(中国标准时间)' 201 | 202 | # 获取图书馆所有的房间和房间 203 | def get_all_room_and_seat(self): 204 | # 注意 老版本的系统需要将url中的seat改为seatengine,且可能需要附带seatId的值 205 | response = self.session.get(url='https://office.chaoxing.com/data/apps/seat/room/list?' 206 | f'deptIdEnc={self.deptIdEnc}') 207 | self.room = response.json()['data']['seatRoomList'] 208 | self.deptId = self.room[0]['deptId'] 209 | for index in self.room: 210 | self.room_id_capacity[index['id']] = index['capacity'] 211 | self.db[index['id']] = 0 212 | self.room_id_name[index['id']] = index['firstLevelName'] + index['secondLevelName'] + index['thirdLevelName'] 213 | response = self.session.get(url='https://office.chaoxing.com/data/apps/seat/seatgrid/roomid?' 214 | 'roomId={}'.format(index['id'])) 215 | self.all_seat += response.json()['data']['seatDatas'] 216 | # print(index['id'], index['capacity'], index['deptId'], index['firstLevelName'], 217 | # index['secondLevelName'], index['thirdLevelName']) 218 | 219 | # 获取学习人数分布 多线程 2000座约10s 220 | # 注意 老版本的系统接口可能不能获取到 221 | def get_study_info(self): 222 | q = queue.Queue() 223 | for item in self.all_seat: 224 | q.put(item) 225 | ths = [] 226 | for idx in range(0, 233): 227 | ths.append( 228 | threading.Thread(target=self.get_seat_info, args=(q,)) 229 | ) 230 | for th in ths: 231 | th.start() 232 | for th in ths: 233 | th.join() 234 | print('有人\t', '没人\t', '总共\t', '地点\t') 235 | for index in self.room: 236 | print(self.db[index['id']], ' ', '\t', self.room_id_capacity[index['id']] - self.db[index['id']], '\t', 237 | self.room_id_capacity[index['id']], '\t', self.room_id_name[index['id']]) 238 | print(self.db['sb'], '\t', self.db['nb'], '\t', len(self.all_seat)) 239 | # 筛选座位 修改145可以看所有楼层的145座位信息 自行发挥 240 | # for index in self.all_seat: 241 | # if index['seatNum'] == '145': 242 | # print(index['seatNum'], index['id'], index['roomId'], self.room_id_name[index['roomId']]) 243 | # continue 244 | 245 | # 获取座位详细信息 配合get_study_info 246 | def get_seat_info(self, q: queue.Queue): 247 | while True: 248 | seat = q.get() 249 | # 注意 老版本的系统不支持此接口 250 | response = self.session.get(url='https://office.chaoxing.com/data/apps/seat/reserve/info?' 251 | 'id={0}&seatNum={1}'.format(seat['roomId'], seat['seatNum'])).json() 252 | # print(response) 253 | try: 254 | r = response["data"]["seatReserve"] 255 | print(r["roomId"], r["seatNum"], r["id"], r["uid"], 256 | self.t_time(r["startTime"]), self.t_time(r["endTime"]), self.room_id_name[r['roomId']]) 257 | self.db[seat['roomId']] += 1 258 | self.db['sb'] += 1 259 | except: 260 | self.db['nb'] += 1 261 | # print(seat['roomId'], seat['seatNum'], '\t无人使用', self.room_id_name[seat['roomId']]) 262 | if q.empty(): 263 | break 264 | 265 | # 查询签到位置范围 没什么卵用 但是官方给了接口 那就安排上 266 | def get_sign_addr(self): 267 | response = self.session.get(url='https://office.chaoxing.com/data/apps/seat/address?' 268 | f'deptId={self.deptId}') 269 | for index in response.json()['data']['addressArr']: 270 | print(index['location'], index['offset']) 271 | 272 | # 获取到最近一次预约座位ID 默认的取消 签到 暂离都是默认这个 请自行发挥 273 | def get_my_seat_id(self): 274 | # 注意 老版本的系统需要将url中的seat改为seatengine 275 | response = self.session.get(url='https://office.chaoxing.com/data/apps/seat/reservelist?' 276 | 'indexId=0&' 277 | 'pageSize=100&' 278 | 'type=-1').json()['data']['reserveList'] 279 | return response[0]['id'] 280 | 281 | 282 | --------------------------------------------------------------------------------