本帖最后由 nianboy 于 2022-4-1 10:54 编辑
学校疫情防控图书馆位置需要预约,自己动手写了一个很low的脚本,大佬勿喷.[Python] 纯文本查看 复制代码 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)[0]
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[i]["week"] == week:
dict = {}
dict["startTime"] = page_dicts[i]["startTime"]
dict["endTime"] = page_dicts[i]["endTime"]
dict["id"] = page_dicts[i]["id"]
dict["week"] = page_dicts[i]["week"]
today_time.append(dict)
pf = pd.DataFrame(list(today_time), index=[1, 2, 3])
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[i]["startTime"]
end = self.nowtime + " " + today_time[i]["endTime"]
id = today_time[i]["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()
|