Created
December 27, 2023 02:57
-
-
Save MacKenia/6c62800e78fbd16cd501cdc494a86322 to your computer and use it in GitHub Desktop.
Demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import base64 as bs | |
import json, re, time | |
from PIL import Image | |
from io import BytesIO | |
import bs4 as Bss | |
import requests as rts | |
from pyDes import ECB, PAD_PKCS5, des | |
class CQReserve: | |
def __init__(self): | |
# 羽毛球馆 301 8 | |
# 风雨球场网球场地 321 4 | |
# 乒乓球馆 322 8 | |
# 室外网球场 302 6 | |
self.main_se = rts.session() | |
self.room_name = { | |
"301": "羽毛球馆", | |
"321": "风雨球场网球场地", | |
"322": "乒乓球馆", | |
"302": "室外网球馆" | |
} | |
self.room_space = { | |
"301": 8, | |
"321": 4, | |
"322": 8, | |
"302": 6 | |
} | |
self.index_url = "http://202.202.209.15:8081/index.html" | |
self.ver_image = "https://csxrz.cqnu.edu.cn:443/cas/verCode?random==" | |
self.login_url = "https://csxrz.cqnu.edu.cn/cas/login?service=http%3A%2F%2F202.202.209.15%3A8081%2Findex.html" | |
self.quire_url = "https://gym.cqnu.edu.cn/app/product/findOkArea.html?s_date=2023-02-08&serviceid=" | |
self.quire_url = "https://gym.cqnu.edu.cn/app/product/findOkArea.html" | |
self.book_url = "https://gym.cqnu.edu.cn/app/order/tobook.html" | |
self.getarea_url = "https://gym.cqnu.edu.cn/app/product/getarea.html?s_dates=2023-02-28&serviceid=321" | |
self.normal_headers = { | |
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36" | |
} | |
self.timeTable = ["08:30-09:30","09:31-10:30","10:31-11:30","11:31-12:30","12:31-13:30", | |
"13:31-14:30","14:31-15:30","15:31-16:30","16:31-17:30","17:31-18:30", | |
"18:31-19:30","19:31-20:30","20:31-21:30"] | |
def deVer(self, ver): | |
""" | |
验证码识别 | |
方法一: | |
使用 ddddocr | |
如果你安装了此依赖 | |
方法二: | |
验证码解析接口 | |
https://market.aliyun.com/products/57124001/cmapi027426.html?spm=5176.2020520132.101.1.45ab72185BHAcX#sku=yuncode2142600000 | |
注册成功后 复制APPCODE | |
粘贴到headers 中 | |
示例:注意空格 | |
"Authorization":"APPCODE 你的APPCODE" | |
方法三: | |
手动识别验证码 | |
""" | |
code = False | |
# 方法一: | |
try: | |
import ddddocr | |
ocr = ddddocr.DdddOcr() | |
code = ocr.classification(ver) | |
except: | |
print("can't import ddddocr switch to another decode method") | |
finally: | |
if code: | |
return code | |
# 方法二: | |
ascii_ver = bs.b64encode(ver).decode('ascii') | |
headers = { | |
"image": ascii_ver, | |
"type": "1001", | |
"Authorization": "APPCODE <your token>" | |
} | |
url = "https://302307.market.alicloudapi.com/ocr/captcha" | |
res = rts.post(url, headers=headers) | |
if res and res.json()["code"] == 0: | |
return res.json()["data"]["captcha"] | |
else: | |
print(res.headers["X-Ca-Error-Message"]) | |
print("can't decode through network API switch to the last decode method") | |
img = Image.open(BytesIO(ver)) | |
img.show() | |
time.sleep(1.5) | |
return input("请输入验证码: ") | |
def encrypt_des(self, data, key): | |
k = des(key, ECB, key, pad=None, padmode=PAD_PKCS5) | |
en = k.encrypt(data.encode('utf-8'), padmode=PAD_PKCS5) | |
return str(bs.b64encode(en), 'utf-8') | |
def login(self, user: str, passwd: str): | |
""" | |
登录 | |
""" | |
ping = self.main_se.get(self.index_url, headers=self.normal_headers) | |
pings = Bss.BeautifulSoup(ping.text, "html.parser") | |
# print(type(pings)) | |
ping_inputs = pings.find_all("input") | |
ver_img = self.main_se.get( | |
self.ver_image + str(int(time.time()*100)), headers=self.normal_headers) | |
ver_code = self.deVer(ver_img.content) | |
print(ver_code) | |
key = ping_inputs[4].get("value")[:8] | |
execution = ping_inputs[5].get("value") | |
password = self.encrypt_des(passwd, key) | |
data = { | |
"username": user, | |
"password": password, | |
"authCode": ver_code, | |
"lt": ping_inputs[4].get("value"), | |
"execution": execution, | |
"_eventId": "submit", | |
"isQrSubmit": "false", | |
"isMobileLogin": "false", | |
"qrValue": "" | |
} | |
login_res = self.main_se.post( | |
self.login_url, data=data, headers=self.normal_headers) | |
# print(login_res.text) | |
if login_res.content.decode('utf-8').find("梦厅") != login_res.content.decode("utf-8").find("场地"): | |
print("登录成功") | |
return True | |
else: | |
print("登录失败,请重试") | |
return False | |
def findArea(self, date, area) -> list: | |
param = { | |
"s_data": date, | |
"serviceid": area | |
} | |
res = self.main_se.get( | |
self.quire_url, param=param, headers=self.normal_headers | |
) | |
if not res: | |
print("网络错误,请重试") | |
return | |
return res.json()["object"] | |
def bookTable(self, table:list): | |
av = "[✓]" | |
bu = "[✕]" | |
print(f'{table[0]["stock"]["s_date"]} 的 {self.room_name[table[0]["stock"]["serviceid"]]} 共有 {len(table)} 个空闲场地') | |
print("以下是详细信息:") | |
for i in range(len(self.timeTable)): | |
print(self.timeTable[i],end="\t") | |
for j in range(self.room_space[table[0]["stock"]["serviceid"]]): | |
if | |
data = { | |
"param": { | |
"stockdetail":{}, | |
"serviceid": "", | |
"stockid": "", | |
"remark": "" | |
}, | |
"num": 0, | |
"json": True | |
} | |
def bookArea(self): | |
pass | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment