超星学习通图书馆预约python脚本
本帖最后由 nianboy 于 2022-4-1 10:54 编辑学校疫情防控图书馆位置需要预约,自己动手写了一个很low的脚本,大佬勿喷.import requests
import re
import json
import datetime
import pandas as pd
class ChaoXing:
def __init__(self, itemId, reserveId):
self.reserveId = reserveId
self.itemId = itemId
today = datetime.datetime.now()
self.nowtime = today.strftime("%Y-%m-%d")
self.lasttime = (today + datetime.timedelta(days=1)).strftime("%Y-%m-%d")
self.headers = {
"User-agent": "Mozilla/4.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36",
}
self.session = requests.session()
def sceen_data(self):
global today_time
url = (
"http://office.chaoxing.com/front/web/apps/reservepc/item?itemId="
+ str(self.itemId)
+ "&reserveId="+ str(self.reserveId)+"&fidEnc=bb3acc50f157286e"
)
login_api = "https://passport2.chaoxing.com/api/login"
params = {
"name": "",#学习通账号
"pwd": "",#学习通密码
"verify": "0",
"schoolid": "",
}
self.session.get(login_api, params=params, headers=self.headers)
r1 = self.session.post(url=url, headers=self.headers).text
self.token = re.findall(r"_this, {}, '(.*?)'", r1)
url = (
"http://office.chaoxing.com/data/apps/reserve/item/setting?reserveId="
+ str(self.reserveId)
+ "&itemId="
+ str(self.itemId)
)
page_text = self.session.get(url=url, headers=self.headers).text
page_dict = json.loads(page_text)
page_dicts = page_dict["data"]["reserveIntervalList"]
today_time = []
for i in range(len(page_dicts)):
week = datetime.datetime.now().weekday() + 1
if page_dicts["week"] == week:
dict = {}
dict["startTime"] = page_dicts["startTime"]
dict["endTime"] = page_dicts["endTime"]
dict["id"] = page_dicts["id"]
dict["week"] = page_dicts["week"]
today_time.append(dict)
pf = pd.DataFrame(list(today_time), index=)
data_dicts = {
"startTime": "开始时间",
"endTime": "结束时间",
"id": "预约ID",
"week": "week",
}
pf.rename(columns=data_dicts, inplace=True)
print(pf)
def get_sign(self):
global start, end, id
a = int(input("请输入序号"))
for i in range(0, a):
start = self.nowtime + " " + today_time["startTime"]
end = self.nowtime + " " + today_time["endTime"]
id = today_time["id"]
data = {
"itemId": self.itemId,
"reserveId": self.reserveId,
"date": self.nowtime,
"startTime": start,
"endTime": end,
"remark": "",
"intervalIdStr": id,
"token": self.token,
}
r2 = self.session.post(
"http://office.chaoxing.com/data/apps/reserve/submit/reserve",
headers=self.headers,
data=data,
).text
if r2 == '{"data":{"reserveUsers":[],"errData":[]},"success":true}':
print("预约成功!")
else:
print(r2)
if __name__ == "__main__":
chaoxing = ChaoXing(itemId=, reserveId=)#学校id以及图书馆id
chaoxing.sceen_data()
chaoxing.get_sign()
学习学习 吾爱252530 发表于 2022-7-4 23:18
楼主,我会编程 ,但是不知道怎么做这种东西,或者说没有一个让我想起做的玩意,也不知道怎么做,怎么办/?? ...
多练多写,善于利用抓包工具,我也是个小白,多看代码 厉害了,我的友。我这边现在很少有超星的预约系统
厉害了
厉害了
厉害了
厉害了,我的友。 大家给个免费的评分:lol 可以了,起码方便广大大学生 楼主很棒! 继续努力学习提升!永无止境! 请问学校id和图书馆id怎么确定,需要自己预约一次抓包吗 凡人i 发表于 2022-4-1 13:57
请问学校id和图书馆id怎么确定,需要自己预约一次抓包吗
不需要,在预约链接里面就有参数,如果学校没有显示的话就需要抓包了