宿迁某大学逆向

请求文件,一星期执行一次大概

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
import requests
import json
import re

timeout = 20
session = requests.session()


# 登陆请求
def login(username, Password, lt):
headers = {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
"Accept-Encoding": "gzip, deflate", "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
"Cache-Control": "max-age=0", "Connection": "keep-alive", "Content-Length": "174",
"Content-Type": "application/x-www-form-urlencoded",
"Host": "authserver.squ.edu.cn",
"Origin": "http://authserver.squ.edu.cn",
"Referer": "http://authserver.squ.edu.cn/authserver/login?service=https%3A%2F%2Fjwgl.squ.edu.cn%2Fstudent%2Fsso%2Flogin",
"Upgrade-Insecure-Requests": "1",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36 Edg/138.0.0.0"}
url = "http://authserver.squ.edu.cn/authserver/login"
data = {
"username": username,
"password": Password,
"rememberMe": "on",
"_eventId": "submit",
"dllt": "userNamePasswordLogin",
"lt": lt,
"execution": "e1s1",
"rmShown": "11"
}
headers1 = {
"Accept": "application/json",
"method": "GET",
"path": "/student/home/get-current-teach-week",
"Sec-Ch-Ua": '"Not)A;Brand";v="8", "Chromium";v="138", "Microsoft Edge";v="138"',
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
"Cache-Control": "no-cache",
"Connection": "keep-alive",
"Pragma": "no-cache",
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "same-origin",
"User-Agent": "Mozilla/5.0 ", # 标识AJAX请求
"Content-Type": "application/json",
"origin": "https://jwgl.squ.edu.cn/student/home",
"Referer": "https://jwgl.squ.edu.cn/student/home"
}
params = {
'service': 'https://jwgl.squ.edu.cn/student/sso/login?refer=https://jwgl.squ.edu.cn/student/home',
}
print("lt------>", lt)
try:
response1 = session.post(url, headers=headers, data=data, params=params, timeout=timeout)
print(session.cookies.get_dict())
print(response1.url)
# 检查响应状态码(200表示成功)
response1.raise_for_status()
print("第一次请求成功,使用密码登陆")

except requests.exceptions.Timeout:
# 捕获超时异常
print(f"第一次请求超时(超过 {timeout} 秒)")
except requests.exceptions.ConnectionError:
# 捕获连接异常(如网络问题、域名不存在等)
print("第一次请求连接失败(可能是网络问题或域名错误)")
except requests.exceptions.HTTPError as e:
# 捕获HTTP错误(如404、500等状态码)
print("第一次请求连接失败")
except Exception as e:
print(f"第一次请求发生未知错误:{str(e)}")

# 获得cookie
try:
response2 = session.get(response1.url, headers=headers1, timeout=timeout)
print(session.cookies.get_dict())
print(response2.url)
# 检查响应状态码(200表示成功)
response2.raise_for_status()
print("第二次请求成功")
except requests.exceptions.Timeout:
# 捕获超时异常
print(f"第二次请求超时(超过 {timeout} 秒)")
except requests.exceptions.ConnectionError:
# 捕获连接异常(如网络问题、域名不存在等)
print("第二次请求连接失败(可能是网络问题或域名错误)")
except requests.exceptions.HTTPError as e:
# 捕获HTTP错误(如404、500等状态码)
print("第二次请求连接失败")
except Exception:
print("第二次请求未知错误")
try:
a = session.cookies.get_dict()['__pstsid__']
b = session.cookies.get_dict()['SESSION']
url = "https://jwgl.squ.edu.cn/student/home"
cookies = {
"__pstsid__": a,
"SESSION": b
}
except Exception as e:
print(f"发生未知错误:{str(e)}")
# 获得姓名
try:
response = requests.get(url, headers=headers1, cookies=cookies, allow_redirects=True, timeout=timeout)
name = re.findall(r'<span class="info-username">(.*?)</span>', response.text)[0]
print("获取姓名成功")
print(name)
response.raise_for_status()
except requests.exceptions.Timeout:
# 捕获超时异常
print(f"获取姓名请求超时(超过 {timeout} 秒)")
except requests.exceptions.ConnectionError:
# 捕获连接异常(如网络问题、域名不存在等)
print("获取姓名连接失败(可能是网络问题或域名错误)")
except requests.exceptions.HTTPError as e:
# 捕获HTTP错误(如404、500等状态码)
print("获取姓名连接失败")
except Exception as e:
print(f"发生未知错误:{str(e)}")

# 获得学期
url = "https://jwgl.squ.edu.cn/student/for-std/course-table"
try:
response = requests.get(url, headers=headers1, cookies=cookies, allow_redirects=True, timeout=timeout)
result = re.findall(r"var semesters = JSON.parse\(\s*'([\s\S]*?)'\s*\)", response.text)[0]
std_data = json.loads(result.replace('\\', ''))[0]
# 打印当前学期的代号。获得学期开始时间和结束时间,并且输出到本地文件
print("获取学期成功")
print(f'当前学期代号{std_data.get("id")}')
response.raise_for_status()
except requests.exceptions.Timeout:
# 捕获超时异常
print(f"获取学期请求超时(超过 {timeout} 秒)")
except requests.exceptions.ConnectionError:
# 捕获连接异常(如网络问题、域名不存在等)
print("获取学期连接失败(可能是网络问题或域名错误)")
except requests.exceptions.HTTPError as e:
# 捕获HTTP错误(如404、500等状态码)
print("获取学期连接失败")
except Exception as e:
print("获取学期未知错误")
try:
json_data = json.dumps(std_data, indent=2, ensure_ascii=False)
except Exception as e:
print(f"发生未知错误:{str(e)}")

# 使用 "w" 模式:若文件不存在则创建,存在则覆盖原有内容
try:
with open("std_data.json", "w", encoding="utf-8") as f:
f.write(json_data)
print("学期信息写入成功") # 写入成功时的提示

except FileNotFoundError:
# 捕获文件路径不存在的异常(例如目录不存在)
print("错误:文件路径不存在,无法写入")
except PermissionError:
# 捕获权限不足的异常(例如没有写入权限)
print("错误:没有权限写入文件,请检查文件权限")
except IOError as e:
# 捕获其他I/O相关错误(如磁盘空间不足、文件被占用等)
print(f"写入文件时发生I/O错误:{str(e)}")
except Exception as e:
# 捕获其他未预料到的异常
print(f"发生未知错误:{str(e)}")

try:
# 获得课程表
url = "https://jwgl.squ.edu.cn/student/for-std/course-table/semester/{}/print-data?semesterId={}&hasExperiment=true".format(
std_data.get("id"), std_data.get("id"))
except Exception as e:
print(f"发生未知错误:{str(e)}")
try:
response = requests.get(url, headers=headers1, cookies=cookies, allow_redirects=True, timeout=timeout)
print("获取课程表成功")
response.raise_for_status()
except requests.exceptions.Timeout:
# 捕获超时异常
print(f"获取课程表请求超时(超过 {timeout} 秒)")
except requests.exceptions.ConnectionError:
# 捕获连接异常(如网络问题、域名不存在等)
print("获取课程表连接失败(可能是网络问题或域名错误)")
except requests.exceptions.HTTPError as e:
# 捕获HTTP错误(如404、500等状态码)
print("获取课程表连接失败")
except Exception as e:
print(f"获取课程表未知错误:{str(e)}")

try:
course = json.loads(response.text)
newCourse = json.dumps(course, indent=2, ensure_ascii=False)
# print(newCourse)
except Exception as e:
print(f"发生未知错误:{str(e)}")
# 使用 "w" 模式:若文件不存在则创建,存在则覆盖原有内容
try:
# 先判断newCourse是否为空
if not newCourse.strip(): # 考虑空白字符的情况
print("newCourse为空,不执行写入操作")
else:
with open("class.json", "w", encoding="utf-8") as f:
f.write(newCourse)
print("课程表文件写入成功") # 写入成功时的提示

except FileNotFoundError:
# 捕获文件路径不存在的异常(例如目录不存在)
print("错误:文件路径不存在,无法写入")
except PermissionError:
# 捕获权限不足的异常(例如没有写入权限)
print("错误:没有权限写入文件,请检查文件权限")
except IOError as e:
# 捕获其他I/O相关错误(如磁盘空间不足、文件被占用等)
print(f"写入文件时发生I/O错误:{str(e)}")
except Exception as e:
# 捕获其他未预料到的异常
print(f"写入文件时发生未知错误:{str(e)}")


# 获取密钥请求
def first(timeout):
headers = {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
"Accept-Encoding": "gzip, deflate", "Accept-Language": "zh-CN,zh;q=0.9", "Cache-Control": "max-age=0",
"Connection": "keep-alive", "Host": "authserver.squ.edu.cn", "Upgrade-Insecure-Requests": "1",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36"
}
url = "http://authserver.squ.edu.cn/authserver/login"
params = {
'service': "https://jwgl.squ.edu.cn/student/sso/login"
}
try:
# 发送GET请求,设置超时时间(单位:秒)
# timeout 可以是一个元组 (连接超时, 读取超时),也可以是单个值(同时设置两者)
response = session.get(url, headers=headers, params=params, timeout=timeout)
lt = re.findall(r'<input type="hidden" name="lt" value="(.*?)"', response.text)[0]
# 检查响应状态码(200表示成功)
response.raise_for_status()
print("lt获取成功")
return lt

except requests.exceptions.Timeout:
# 捕获超时异常
print(f"请求超时(超过 {timeout} 秒)")
except requests.exceptions.ConnectionError:
# 捕获连接异常(如网络问题、域名不存在等)
print("连接失败(可能是网络问题或域名错误)")
except requests.exceptions.HTTPError as e:
# 捕获HTTP错误(如404、500等状态码)
print("连接失败")
except Exception as e:
print("未知错误")


if __name__ == '__main__':

try:
lt = first(timeout)


#---------------------------------
#此处填写学号,密码
login("学号", "密码", lt)
except Exception:
print("登陆失败")

try:
with open("class.json", "r", encoding="utf-8") as file: # "r"表示只读模式
content = file.read() # 读取全部内容
# 判断内容是否为空
if not content.strip(): # 使用strip()避免空白字符被误认为有效内容
print("文件内容为空不处理")
else:
print("文件内容不为空,开始处理数据...")
classData = json.loads(content)
dict_list = []

# print(classData.get("studentTableVms")[0].get("activities"))
for activity in classData.get("studentTableVms")[0].get("activities"):
newClass = {}
newClass["courseName"] = activity.get("courseName")
newClass["room"] = activity.get("room")
newClass["weekIndexes"] = activity.get("weekIndexes")
newClass["weekday"] = activity.get("weekday")
newClass["startUnit"] = activity.get("startUnit")
newClass["endUnit"] = activity.get("endUnit")
dict_list.append(newClass)
# print(dict_list)
# print(json.dumps(dict_list, ensure_ascii=False, indent=2))
# 1. 写出文本文件(覆盖模式)
# 使用 "w" 模式:若文件不存在则创建,存在则覆盖原有内容
with open("classNew.json", "w", encoding="utf-8") as f:
f.write(json.dumps(dict_list, ensure_ascii=False, indent=2))


except Exception as e:

print(f"覆盖文件失败:{str(e)}")

微信推送到公众号

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
import json
from datetime import datetime
import requests

# 从测试号信息获取
#入口https://mp.weixin.qq.com/debug/cgi-bin/sandboxinfo?action=showinfo&t=sandbox/index
appID = ""
appSecret = ""
# 收信人ID即 用户列表中的微信号,见上文
openId = ["", ""]
# 测试模版
template_id = ""

with open("classNew.json", "r", encoding="utf-8") as file: # "r"表示只读模式
content = file.read() # 读取全部内容
Data = json.loads(content)
newData = []

for item in Data:
room = item.get("room").split()[0]
item["room"] = room
if item.get("courseName") == '毛泽东思想和中国特色社会主义理论体系概论':
item["courseName"] = "毛概"

for item in Data:
print(item)
newData.append(item)

with open("minNameclassNew.json", "w", encoding="utf-8") as f:
f.write(json.dumps(newData, ensure_ascii=False, indent=2))

with open("minNameclassNew.json", "r", encoding="utf-8") as file: # "r"表示只读模式
content = file.read() # 读取全部内容
Data = json.loads(content)

with open("std_data.json", "r", encoding="utf-8") as std_time: # "r"表示只读模式
std_data = std_time.read() # 读取全部内容
data = json.loads(std_data)
startDate = data.get("startDate")
endDate = data.get("endDate")


def get_course(weekIndex, weekDay):
class_std = {}
class_all = {}
end_class = []
dto_class = {}
for course in Data:
for week in course.get("weekIndexes"):
if (weekIndex == week) and (course.get("weekday") == weekDay):
single_class = {}
print(
f'星期{weekDay} {course.get("courseName")}{course.get("startUnit")}-{course.get("endUnit")} 有课 在{course.get("room")}')
class_std[course.get(
"startUnit")] = f'星期{weekDay} {course.get("courseName")}{course.get("startUnit")}-{course.get("endUnit")} 有课 在{course.get("room")}'
single_class["courseName"] = course.get("courseName")
single_class["room"] = course.get("room")
single_class["startUnit"] = course.get("startUnit")
single_class["endUnit"] = course.get("endUnit")
class_all[course.get("startUnit")] = single_class
# print(class_std)
# class_all
i = 0
for item in sorted(class_all.items(), key=lambda x: x[0]):
end_class.append(item[1])
i = i + 1
# print(json.dumps(end_class, ensure_ascii=False, indent=2))
dto_class["day"] = weekDay
dto_class["course"] = end_class
print(json.dumps(dto_class, ensure_ascii=False, indent=2))
return dto_class, i


def get_week_number(start_date_str, end_date_str, current_date_str=None):
"""
计算当前日期在[开始日期, 结束日期]范围内是第几周

参数:
start_date_str: 开始日期字符串,格式"YYYY-MM-DD"
end_date_str: 结束日期字符串,格式"YYYY-MM-DD"
current_date_str: 要计算的日期字符串,默认为今天

返回:
int: 周数(如果当前日期不在范围内则返回None)
"""
try:
# 转换字符串为日期对象
start_date = datetime.strptime(start_date_str, "%Y-%m-%d").date()
end_date = datetime.strptime(end_date_str, "%Y-%m-%d").date()

# 如果未指定当前日期,则使用今天
if current_date_str:
current_date = datetime.strptime(current_date_str, "%Y-%m-%d").date()
else:
current_date = datetime.today().date()

# 检查当前日期是否在范围内
if not (start_date <= current_date <= end_date):
print(f"今天{current_date}不在{start_date_str}{end_date_str}范围内")
return None, current_date.isoweekday()

# 计算当前日期与开始日期的天数差
days_diff = (current_date - start_date).days

# 计算周数(注意:这里将开始日期所在周视为第1周)
week_number = (days_diff // 7) + 1
if week_number:
print(f"今天{current_date}{start_date_str}{end_date_str}期间的第{week_number}周")
return week_number, current_date.isoweekday()


except ValueError as e:
print(f"日期格式错误: {e}")
return None


# def get_weather(my_city):
# urls = ["http://www.weather.com.cn/textFC/hb.shtml",
# "http://www.weather.com.cn/textFC/db.shtml",
# "http://www.weather.com.cn/textFC/hd.shtml",
# "http://www.weather.com.cn/textFC/hz.shtml",
# "http://www.weather.com.cn/textFC/hn.shtml",
# "http://www.weather.com.cn/textFC/xb.shtml",
# "http://www.weather.com.cn/textFC/xn.shtml"
# ]
# for url in urls:
# resp = requests.get(url)
# text = resp.content.decode("utf-8")
# soup = BeautifulSoup(text, 'html5lib')
# div_conMidtab = soup.find("div", class_="conMidtab")
# tables = div_conMidtab.find_all("table")
# for table in tables:
# trs = table.find_all("tr")[2:]
# for index, tr in enumerate(trs):
# tds = tr.find_all("td")
# # 这里倒着数,因为每个省会的td结构跟其他不一样
# city_td = tds[-8]
# this_city = list(city_td.stripped_strings)[0]
# if this_city == my_city:
# high_temp_td = tds[-5]
# low_temp_td = tds[-2]
# weather_type_day_td = tds[-7]
# weather_type_night_td = tds[-4]
# wind_td_day = tds[-6]
# wind_td_day_night = tds[-3]
#
# high_temp = list(high_temp_td.stripped_strings)[0]
# low_temp = list(low_temp_td.stripped_strings)[0]
# weather_typ_day = list(weather_type_day_td.stripped_strings)[0]
# weather_type_night = list(weather_type_night_td.stripped_strings)[0]
#
# wind_day = list(wind_td_day.stripped_strings)[0] + list(wind_td_day.stripped_strings)[1]
# wind_night = list(wind_td_day_night.stripped_strings)[0] + list(wind_td_day_night.stripped_strings)[
# 1]
#
# # 如果没有白天的数据就使用夜间的
# temp = f"{low_temp}—{high_temp}摄氏度" if high_temp != "-" else f"{low_temp}摄氏度"
# weather_typ = weather_typ_day if weather_typ_day != "-" else weather_type_night
# wind = f"{wind_day}" if wind_day != "--" else f"{wind_night}"
# return f"{this_city} {weather_typ} {temp} {wind}"


def get_weather(my_city):
response = requests.get("http://t.weather.itboy.net/api/weather/city/101191301").text
weather = json.loads(response)

print(weather.get("cityInfo").get("city"))
city = weather.get("cityInfo").get("city")
print(weather.get("data").get("forecast")[0].get("type"))
type = weather.get("data").get("forecast")[0].get("type")
print(weather.get("data").get("forecast")[0].get("high"))
max = f'{weather.get("data").get("forecast")[0].get("high")}'
print(weather.get("data").get("forecast")[0].get("low"))
min = f'{weather.get("data").get("forecast")[0].get("low")}'
print(weather.get("data").get("forecast")[0].get("fx"))
fx = weather.get("data").get("forecast")[0].get("fx")
print(weather.get("data").get("forecast")[0].get("fl"))
fl = weather.get("data").get("forecast")[0].get("fl")
return f"{city},{type},{min.split(' ', 1)[1]}--{max.split(' ', 1)[1]},{fx}{fl}"


def getSentence():
cookies = {
"X-User-Token": "9Ha8iJrQB2fEVU1UspVL6kkh8cL9n8ry"
}
response = requests.get("https://v2.jinrishici.com/sentence", cookies=cookies)
sentence = json.loads(response.text).get("data").get("content")
print(sentence)
return sentence


def getAccessKey():
body = {
"grant_type": "client_credential",
"appid": appID,
"secret": appSecret,
}
url = "https://api.weixin.qq.com/cgi-bin/stable_token"
response = requests.post(url, json=body).json()
print(response.get("access_token"))
return response.get("access_token")


# 向微信发送信息
def sendMessage(openIditem,AccessKey, content):
lass_pear = {
'1': -1,
'3': -1,
'5': -1,
'7': -1,
}
j = 0
for item in content.get("course").get("course"):
num = item.get("startUnit")
if num == 1:
lass_pear["1"] = j
j = j + 1
if num == 3:
lass_pear["3"] = j
j = j + 1
if num == 5:
lass_pear["5"] = j
j = j + 1
if num == 7:
lass_pear["7"] = j
j = j + 1
print(lass_pear)
params = {
"access_token": AccessKey,
'semesterId': '66',
'hasExperiment': 'true'
}
body = {

"touser": openIditem,
"template_id": template_id,
"url": "http://weixin.qq.com",

"topcolor": "#FF0000",

"data": {

"keywords1": {

"value": content.get("current_date"),

}, "keywords2": {

"value": content.get("courseCount"),

}, "keywords3": {

"value": f'{(content.get("course").get("course")[lass_pear["1"]]).get("courseName")} {content.get("course").get("course")[lass_pear["1"]].get("room")} {content.get("course").get("course")[lass_pear["1"]].get("startUnit")} {content.get("course").get("course")[lass_pear["1"]].get("endUnit")}' if
lass_pear["1"] != -1 else '',

}, "keywords4": {

"value": f'{(content.get("course").get("course")[lass_pear["3"]]).get("courseName")} {content.get("course").get("course")[lass_pear["3"]].get("room")} {content.get("course").get("course")[lass_pear["3"]].get("startUnit")} {content.get("course").get("course")[lass_pear["3"]].get("endUnit")}' if
lass_pear["3"] != -1 else '',

}, "keywords5": {

"value": f'{(content.get("course").get("course")[lass_pear["5"]]).get("courseName")} {content.get("course").get("course")[lass_pear["5"]].get("room")} {content.get("course").get("course")[lass_pear["5"]].get("startUnit")} {content.get("course").get("course")[lass_pear["5"]].get("endUnit")}' if
lass_pear["5"] != -1 else '',

}, "keywords6": {

"value": f'{(content.get("course").get("course")[lass_pear["7"]]).get("courseName")} {content.get("course").get("course")[lass_pear["7"]].get("room")} {content.get("course").get("course")[lass_pear["7"]].get("startUnit")} {content.get("course").get("course")[lass_pear["7"]].get("endUnit")}' if
lass_pear["7"] != -1 else '',

}, "keywords7": {

"value": content.get("weather"),

}, "keywords8": {

"value": content.get("sentence"),

}

}

}
url = "https://api.weixin.qq.com/cgi-bin/message/template/send"
response = requests.post(url, params=params, json=body).json()
print(response)


# 使用示例
if __name__ == "__main__":
result = {}
# 计算今天是第几周
# current_week, weekDay = get_week_number(startDate, endDate)
# specific_date = "2025-9-6"
current_week, weekDay = get_week_number(startDate, endDate)
if current_week:
course, courseCount = get_course(current_week, weekDay)
else:
courseCount = 0
course = {
"day": weekDay,
"course": []
}
weather = get_weather("宿迁")
print(f"天气信息: {weather}")
sentence = getSentence()
current_date = datetime.today().strftime("%Y年%m月%d日")
result["current_date"] = f"{current_date}星期{weekDay}"
result["courseCount"] = courseCount
result["course"] = course
result["weather"] = weather
result["sentence"] = sentence
print(json.dumps(result, ensure_ascii=False, indent=2))
str_result = json.dumps(result, ensure_ascii=False, indent=2)

AccessKey = getAccessKey()
for item in openId:
sendMessage(item, AccessKey, json.loads(str_result))
# sendMessage(AccessKey, json.loads(str_result))