Skip to content

Commit fc59635

Browse files
authored
修复bugs
1 parent 3a820a5 commit fc59635

File tree

14 files changed

+329
-228
lines changed

14 files changed

+329
-228
lines changed

README.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div align="center">
2-
<img src="https://img1.imgtp.com/2023/10/06/NChUNeiA.png" alt="TeenStudy.png" border="0" width="500px" height="500px"/>
2+
<img src="https://www.freeimg.cn/i/2023/12/03/656c227814852.png" alt="TeenStudy.png" border="0" width="500px" height="500px"/>
33
<h1>TeenStudy</h1>
44
<b>基于nonebot2和OneBotV11的青年大学习自动提交插件,用于自动完成大学习,在后台留下记录,返回完成截图</b>
55
<br/>
@@ -39,8 +39,8 @@
3939
| 共青团名称 | 开发状态 | 备注 |
4040
| :----------: | :------: | :--------------------------: |
4141
| 青春湖北 | 支持 | 无需抓包,支持提交往期青年大学习 |
42-
| 江西共青团 | 支持 | 无需抓包,支持提交往期青年大学习 |
43-
| 安徽共青团 | 支持 | 无需抓包,不支持提交往期青年大学习,限制一天只能提交一期 |
42+
| 江西共青团 | 支持 | 无需抓包,不支持提交往期青年大学习 |
43+
| 安徽共青团 | 支持 | 无需抓包,不支持提交往期青年大学习 |
4444
| 广东共青团 | 支持 | 无需抓包,不支持提交往期青年大学习 |
4545
| 青春北京 | 支持 | 无需抓包,不支持提交往期青年大学习 |
4646
| 青春上海 | 支持 | 微信扫码绑定,不支持提交往期青年大学习,只能提交最新一期 |
@@ -164,7 +164,16 @@
164164

165165
## 更新日志
166166

167-
### 2023/10/30
167+
### 2023/12/03
168+
169+
- 因江西共青团屏蔽H5端使用,无法简单获取openid,回退之前版本改用伪造openid提交
170+
- 移除对江西地区提交往期大学习支持
171+
- 修复湖北地区提交最新一期失败问题
172+
- 修复获取最新一期大学习报网络延迟无法获取问题
173+
174+
<details>
175+
<summary>2023/10/30</summary>
176+
168177
- **破坏性**·更改青年大学习答案数据库结构,请登录管理后台清空大学习列表后重启
169178
- 增加陕西地区`三秦青年`,token时效待测试
170179
- 增加江西地区提交往期青年大学习功能
@@ -176,6 +185,7 @@
176185
- 修复单独发送`提交大学习`报期数无效问题
177186
- 修复后台Icon图表缺失问题
178187

188+
</details>
179189
<details>
180190
<summary>2023/10/13</summary>
181191

TeenStudy/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ async def startup():
3030
await utils.update.update_answer()
3131
await utils.update.update_shanxi()
3232
await utils.update.update_shandong()
33-
await utils.update.update_jiangxi()
3433

3534

3635
DRIVER.on_shutdown(utils.path.disconnect)

TeenStudy/utils/dxx.py

Lines changed: 35 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import random
23
import re
34
import secrets
45
import time
@@ -63,13 +64,7 @@ async def hubei(user_id: int, catalogue: Optional[str] = None) -> dict:
6364
}
6465
else:
6566
if not catalogue:
66-
resp_url = 'https://h5.cyol.com/special/weixin/sign.json'
67-
async with AsyncClient(headers=headers) as client:
68-
response = await client.get(url=resp_url, timeout=10)
69-
response.encoding = response.charset_encoding
70-
result = response.json()
71-
code_result = list(result)[-1]
72-
answer = await Answer.filter(code=code_result).values()
67+
answer = await Answer.all().order_by("time").values()
7368
catalogue = answer[-1]["catalogue"]
7469
name = result[0]["name"]
7570
openid = result[0]["openid"]
@@ -124,20 +119,13 @@ async def hubei(user_id: int, catalogue: Optional[str] = None) -> dict:
124119
}
125120

126121

127-
async def jiangxi(user_id: int, catalogue: Optional[str] = None) -> dict:
122+
async def jiangxi(user_id: int) -> dict:
128123
"""
129124
江西共青团
130-
:param catalogue:
131125
:param user_id:用户ID
132126
:return:
133127
"""
134128
result = await User.filter(user_id=user_id).values()
135-
if catalogue:
136-
filterArg = {
137-
"title": catalogue
138-
}
139-
else:
140-
filterArg = {}
141129
if not result:
142130
return {
143131
"status": 500,
@@ -147,27 +135,25 @@ async def jiangxi(user_id: int, catalogue: Optional[str] = None) -> dict:
147135
name = result[0]["name"]
148136
nid = result[0]["dxx_id"]
149137
openid = result[0]["openid"]
150-
token = result[0]["token"]
151138
if result[0]["mobile"]:
152139
suborg = result[0]["mobile"]
153140
else:
154141
suborg = ''
155-
code = await JiangXiDxx.filter(**filterArg).order_by("code").values()
156-
if not code:
157-
return {
158-
"status": 404,
159-
"msg": f"江西共青团没有找到青年大学习{catalogue}"
160-
}
161-
try:
162-
headers.update({
163-
'Cookie': 'JSESSIONID=' + secrets.token_urlsafe(40),
164-
'Host': 'www.jxqingtuan.cn',
165-
'Origin': 'http://www.jxqingtuan.cn',
166-
'Referer': 'http://www.jxqingtuan.cn/html/h5_index.html?&accessToken=' + openid,
167-
'openid': openid
168-
})
169-
async with AsyncClient(headers=headers) as client:
170-
course = code[-1]["code"]
142+
answer = await Answer.all().order_by("time").values()
143+
# try:
144+
url = f"http://www.jxqingtuan.cn/pub/pub/vol/volClass/index?userId={random.randint(4363000, 4364000)}"
145+
headers.update({
146+
'Cookie': 'JSESSIONID=' + secrets.token_urlsafe(40),
147+
'Host': 'www.jxqingtuan.cn',
148+
'Origin': 'http://www.jxqingtuan.cn',
149+
'Referer': 'http://www.jxqingtuan.cn/html/h5_index.html?&accessToken=' + openid,
150+
})
151+
async with AsyncClient(headers=headers) as client:
152+
course = await client.get(url=url)
153+
course.encoding = course.charset_encoding
154+
if json.loads(course.text).get('code') == 0:
155+
title = json.loads(course.text).get("list")[0].get("title")
156+
course = json.loads(course.text).get('list')[0].get('id')
171157
resp_url = 'http://www.jxqingtuan.cn/pub/pub/vol/volClass/join?accessToken='
172158
data = {"course": course, "nid": nid, "cardNo": name, "subOrg": suborg}
173159
res = await client.post(url=resp_url, json=data)
@@ -176,43 +162,33 @@ async def jiangxi(user_id: int, catalogue: Optional[str] = None) -> dict:
176162
if resp.get("status") == 200:
177163
await User.filter(user_id=user_id).update(
178164
commit_time=time.time(),
179-
catalogue=catalogue
165+
catalogue=title
180166
)
181-
await commit(user_id=user_id, catalogue=catalogue, status=True)
182-
data = {
183-
"check": 1,
184-
"type": 3,
185-
"title": "青年大学习",
186-
"url": code[-1]['url'],
187-
"openid": openid,
188-
"userId": token
189-
}
190-
response = await client.post('http://www.jxqingtuan.cn/pub/pub/vol/member/addScoreInfo',
191-
params=data)
192-
if response.json()["code"] == "200" or response.json()["code"] == "-1":
193-
return {
194-
"status": 0,
195-
"catalogue": catalogue,
196-
"msg": "提交成功!"
197-
}
167+
await commit(user_id=user_id, catalogue=title, status=True)
198168
return {
199169
"status": 0,
200-
"catalogue": catalogue,
170+
"catalogue": title,
201171
"msg": "提交成功!"
202172
}
203173
else:
204-
await commit(user_id=user_id, catalogue=catalogue, status=False)
174+
await commit(user_id=user_id, catalogue=title, status=False)
205175
return {
206176
"status": 500,
207177
"msg": "提交失败,信息错误!"
208178
}
209-
except Exception as e:
210-
logger.error(e)
211-
await commit(user_id=user_id, catalogue=catalogue, status=False)
212-
return {
213-
"status": 500,
214-
"msg": f"提交失败,{e}"
215-
}
179+
else:
180+
await commit(user_id=user_id, catalogue=answer[-1]["catalogue"], status=False)
181+
return {
182+
"status": 500,
183+
"msg": "提交失败,江西共青团访问错误!"
184+
}
185+
# except Exception as e:
186+
# logger.error(e)
187+
# await commit(user_id=user_id, catalogue=answer[-1]["catalogue"], status=False)
188+
# return {
189+
# "status": 500,
190+
# "msg": f"提交失败,{e}"
191+
# }
216192

217193

218194
async def zhejiang(user_id: int) -> dict:

TeenStudy/utils/update.py

Lines changed: 4 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,14 @@ async def dxxInfo(url: str) -> dict:
133133

134134
async def update_shanxi():
135135
url = f"https://api.sxgqt.org.cn/h5sxapiv2/study/studyLink"
136-
headers.update({
136+
headers={
137137
"Host": "api.sxgqt.org.cn",
138138
"accept": "application/json",
139139
"x-requested-with": "XMLHttpRequest",
140140
"user-agent": "Mozilla/5.0 (Linux; Android 13; 23049RAD8C Build/TKQ1.221114.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/111.0.5563.116 Mobile Safari/537.36 XWEB/5317 MMWEBSDK/20230701 MMWEBID/6170 MicroMessenger/8.0.40.2420(0x28002837) WeChat/arm64 Weixin NetType/WIFI Language/zh_CN ABI/arm64",
141141
"version": "H5_3.2.0",
142142
"origin": "https://h5.sxgqt.org.cn"
143-
})
143+
}
144144
try:
145145
async with AsyncClient(headers=headers) as client:
146146
response = await client.get(url=url)
@@ -187,54 +187,8 @@ async def update_shanxi():
187187
logger.error(e)
188188

189189

190-
async def update_jiangxi():
191-
url = f"http://www.jxqingtuan.cn/pub/pub/vol/volClass/index?userId={random.randint(4363000, 4364000)}&&page=1&pageSize=100"
192-
headers.update({
193-
'Cookie': 'JSESSIONID=' + secrets.token_urlsafe(40),
194-
'Host': 'www.jxqingtuan.cn',
195-
'Origin': 'http://www.jxqingtuan.cn',
196-
'Referer': 'http://www.jxqingtuan.cn/html/h5_index.html?&accessToken=' + ''.join(
197-
random.sample(string.ascii_letters + string.digits, 28)),
198-
})
199-
try:
200-
async with AsyncClient(headers=headers) as client:
201-
response = await client.get(url=url)
202-
response.encoding = response.charset_encoding
203-
if response.json().get('code', -1) == 0:
204-
dxxList = response.json().get("list", [])
205-
for item in dxxList:
206-
if await JiangXiDxx.filter(code=item.get("id", -1)).count():
207-
continue
208-
dxxResult = await dxxInfo(
209-
item.get("url").replace("index.html", "m.html").replace("http://", "https://"))
210-
if dxxResult["status"]:
211-
await JiangXiDxx.create(
212-
time=time.time(),
213-
score=item.get("score", 0),
214-
addtime=item.get("addtime", "1970-01-01 00:00:00"),
215-
endtime=item.get("endtime", "1970-01-01 00:00:00"),
216-
code=item.get("id", -2),
217-
starttime=item.get("starttime", "1970-01-01 00:00:00"),
218-
title=dxxResult["catalogue"],
219-
url=item.get("url", "https://h5.cyol.com/special/weixin/sign.json")
220-
)
221-
else:
222-
await JiangXiDxx.create(
223-
time=time.time(),
224-
score=item.get("score", 0),
225-
addtime=item.get("addtime", "1970-01-01 00:00:00"),
226-
endtime=item.get("endtime", "1970-01-01 00:00:00"),
227-
code=item.get("id", -2),
228-
starttime=item.get("starttime", "1970-01-01 00:00:00"),
229-
title=item.get("title", "青年大学习"),
230-
url=item.get("url", "https://h5.cyol.com/special/weixin/sign.json")
231-
)
232-
except Exception as e:
233-
logger.error(e)
234-
235-
236190
async def update_shandong():
237-
headers.update({
191+
headers={
238192
"Host": "qndxx.youth54.cn",
239193
"Connection": "keep-alive",
240194
"Accept": "*/*",
@@ -245,7 +199,7 @@ async def update_shandong():
245199
"Referer": "http://qndxx.youth54.cn/SmartLA/dxx.w?method=pageSdtwdt",
246200
"Accept-Encoding": "gzip, deflate",
247201
"Accept-Language": "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7",
248-
})
202+
}
249203
new_version_url = f'http://qndxx.youth54.cn/SmartLA/dxxjfgl.w?method=getNewestVersionInfo'
250204
try:
251205
async with AsyncClient(headers=headers) as client:
@@ -358,10 +312,6 @@ async def update_data():
358312
logger.error(e)
359313
except Exception as e:
360314
logger.error(e)
361-
# try:
362-
await update_jiangxi()
363-
# except Exception as e:
364-
# logger.error(e)
365315
await update_shandong()
366316
await update_shanxi()
367317

@@ -373,7 +323,6 @@ async def check_apply():
373323
except ValueError as e:
374324
return
375325
apply_list = await AddUser.filter(status="未通过").values()
376-
377326
for item in apply_list:
378327
result = await User.filter(user_id=item["user_id"], group_id=item["group_id"]).count()
379328
if result:

TeenStudy/utils/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ async def distribute_area(user_id: int, area: str, catalogue: Optional[str] = No
483483
if area == "湖北":
484484
return await dxx.hubei(user_id=user_id, catalogue=catalogue)
485485
elif area == "江西":
486-
return await dxx.jiangxi(user_id=user_id, catalogue=catalogue)
486+
return await dxx.jiangxi(user_id=user_id)
487487
elif area == "浙江":
488488
return await dxx.zhejiang(user_id=user_id)
489489
elif area == "上海":

TeenStudy/web/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
},
3030
'''
3131
DRIVER = get_driver()
32-
icon_path = 'https://img1.imgtp.com/2023/10/06/NChUNeiA.png'
32+
icon_path = 'https://www.freeimg.cn/i/2023/12/03/656c227814852.png'
3333

3434

3535
@DRIVER.on_startup

0 commit comments

Comments
 (0)