Skip to content

Commit

Permalink
修复bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ZM25XC authored Dec 3, 2023
1 parent 3a820a5 commit fc59635
Show file tree
Hide file tree
Showing 14 changed files with 329 additions and 228 deletions.
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div align="center">
<img src="https://img1.imgtp.com/2023/10/06/NChUNeiA.png" alt="TeenStudy.png" border="0" width="500px" height="500px"/>
<img src="https://www.freeimg.cn/i/2023/12/03/656c227814852.png" alt="TeenStudy.png" border="0" width="500px" height="500px"/>
<h1>TeenStudy</h1>
<b>基于nonebot2和OneBotV11的青年大学习自动提交插件,用于自动完成大学习,在后台留下记录,返回完成截图</b>
<br/>
Expand Down Expand Up @@ -39,8 +39,8 @@
| 共青团名称 | 开发状态 | 备注 |
| :----------: | :------: | :--------------------------: |
| 青春湖北 | 支持 | 无需抓包,支持提交往期青年大学习 |
| 江西共青团 | 支持 | 无需抓包,支持提交往期青年大学习 |
| 安徽共青团 | 支持 | 无需抓包,不支持提交往期青年大学习,限制一天只能提交一期 |
| 江西共青团 | 支持 | 无需抓包,不支持提交往期青年大学习 |
| 安徽共青团 | 支持 | 无需抓包,不支持提交往期青年大学习 |
| 广东共青团 | 支持 | 无需抓包,不支持提交往期青年大学习 |
| 青春北京 | 支持 | 无需抓包,不支持提交往期青年大学习 |
| 青春上海 | 支持 | 微信扫码绑定,不支持提交往期青年大学习,只能提交最新一期 |
Expand Down Expand Up @@ -164,7 +164,16 @@

## 更新日志

### 2023/10/30
### 2023/12/03

- 因江西共青团屏蔽H5端使用,无法简单获取openid,回退之前版本改用伪造openid提交
- 移除对江西地区提交往期大学习支持
- 修复湖北地区提交最新一期失败问题
- 修复获取最新一期大学习报网络延迟无法获取问题

<details>
<summary>2023/10/30</summary>

- **破坏性**·更改青年大学习答案数据库结构,请登录管理后台清空大学习列表后重启
- 增加陕西地区`三秦青年`,token时效待测试
- 增加江西地区提交往期青年大学习功能
Expand All @@ -176,6 +185,7 @@
- 修复单独发送`提交大学习`报期数无效问题
- 修复后台Icon图表缺失问题

</details>
<details>
<summary>2023/10/13</summary>

Expand Down
1 change: 0 additions & 1 deletion TeenStudy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ async def startup():
await utils.update.update_answer()
await utils.update.update_shanxi()
await utils.update.update_shandong()
await utils.update.update_jiangxi()


DRIVER.on_shutdown(utils.path.disconnect)
94 changes: 35 additions & 59 deletions TeenStudy/utils/dxx.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import random
import re
import secrets
import time
Expand Down Expand Up @@ -63,13 +64,7 @@ async def hubei(user_id: int, catalogue: Optional[str] = None) -> dict:
}
else:
if not catalogue:
resp_url = 'https://h5.cyol.com/special/weixin/sign.json'
async with AsyncClient(headers=headers) as client:
response = await client.get(url=resp_url, timeout=10)
response.encoding = response.charset_encoding
result = response.json()
code_result = list(result)[-1]
answer = await Answer.filter(code=code_result).values()
answer = await Answer.all().order_by("time").values()
catalogue = answer[-1]["catalogue"]
name = result[0]["name"]
openid = result[0]["openid"]
Expand Down Expand Up @@ -124,20 +119,13 @@ async def hubei(user_id: int, catalogue: Optional[str] = None) -> dict:
}


async def jiangxi(user_id: int, catalogue: Optional[str] = None) -> dict:
async def jiangxi(user_id: int) -> dict:
"""
江西共青团
:param catalogue:
:param user_id:用户ID
:return:
"""
result = await User.filter(user_id=user_id).values()
if catalogue:
filterArg = {
"title": catalogue
}
else:
filterArg = {}
if not result:
return {
"status": 500,
Expand All @@ -147,27 +135,25 @@ async def jiangxi(user_id: int, catalogue: Optional[str] = None) -> dict:
name = result[0]["name"]
nid = result[0]["dxx_id"]
openid = result[0]["openid"]
token = result[0]["token"]
if result[0]["mobile"]:
suborg = result[0]["mobile"]
else:
suborg = ''
code = await JiangXiDxx.filter(**filterArg).order_by("code").values()
if not code:
return {
"status": 404,
"msg": f"江西共青团没有找到青年大学习{catalogue}"
}
try:
headers.update({
'Cookie': 'JSESSIONID=' + secrets.token_urlsafe(40),
'Host': 'www.jxqingtuan.cn',
'Origin': 'http://www.jxqingtuan.cn',
'Referer': 'http://www.jxqingtuan.cn/html/h5_index.html?&accessToken=' + openid,
'openid': openid
})
async with AsyncClient(headers=headers) as client:
course = code[-1]["code"]
answer = await Answer.all().order_by("time").values()
# try:
url = f"http://www.jxqingtuan.cn/pub/pub/vol/volClass/index?userId={random.randint(4363000, 4364000)}"
headers.update({
'Cookie': 'JSESSIONID=' + secrets.token_urlsafe(40),
'Host': 'www.jxqingtuan.cn',
'Origin': 'http://www.jxqingtuan.cn',
'Referer': 'http://www.jxqingtuan.cn/html/h5_index.html?&accessToken=' + openid,
})
async with AsyncClient(headers=headers) as client:
course = await client.get(url=url)
course.encoding = course.charset_encoding
if json.loads(course.text).get('code') == 0:
title = json.loads(course.text).get("list")[0].get("title")
course = json.loads(course.text).get('list')[0].get('id')
resp_url = 'http://www.jxqingtuan.cn/pub/pub/vol/volClass/join?accessToken='
data = {"course": course, "nid": nid, "cardNo": name, "subOrg": suborg}
res = await client.post(url=resp_url, json=data)
Expand All @@ -176,43 +162,33 @@ async def jiangxi(user_id: int, catalogue: Optional[str] = None) -> dict:
if resp.get("status") == 200:
await User.filter(user_id=user_id).update(
commit_time=time.time(),
catalogue=catalogue
catalogue=title
)
await commit(user_id=user_id, catalogue=catalogue, status=True)
data = {
"check": 1,
"type": 3,
"title": "青年大学习",
"url": code[-1]['url'],
"openid": openid,
"userId": token
}
response = await client.post('http://www.jxqingtuan.cn/pub/pub/vol/member/addScoreInfo',
params=data)
if response.json()["code"] == "200" or response.json()["code"] == "-1":
return {
"status": 0,
"catalogue": catalogue,
"msg": "提交成功!"
}
await commit(user_id=user_id, catalogue=title, status=True)
return {
"status": 0,
"catalogue": catalogue,
"catalogue": title,
"msg": "提交成功!"
}
else:
await commit(user_id=user_id, catalogue=catalogue, status=False)
await commit(user_id=user_id, catalogue=title, status=False)
return {
"status": 500,
"msg": "提交失败,信息错误!"
}
except Exception as e:
logger.error(e)
await commit(user_id=user_id, catalogue=catalogue, status=False)
return {
"status": 500,
"msg": f"提交失败,{e}"
}
else:
await commit(user_id=user_id, catalogue=answer[-1]["catalogue"], status=False)
return {
"status": 500,
"msg": "提交失败,江西共青团访问错误!"
}
# except Exception as e:
# logger.error(e)
# await commit(user_id=user_id, catalogue=answer[-1]["catalogue"], status=False)
# return {
# "status": 500,
# "msg": f"提交失败,{e}"
# }


async def zhejiang(user_id: int) -> dict:
Expand Down
59 changes: 4 additions & 55 deletions TeenStudy/utils/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,14 @@ async def dxxInfo(url: str) -> dict:

async def update_shanxi():
url = f"https://api.sxgqt.org.cn/h5sxapiv2/study/studyLink"
headers.update({
headers={
"Host": "api.sxgqt.org.cn",
"accept": "application/json",
"x-requested-with": "XMLHttpRequest",
"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",
"version": "H5_3.2.0",
"origin": "https://h5.sxgqt.org.cn"
})
}
try:
async with AsyncClient(headers=headers) as client:
response = await client.get(url=url)
Expand Down Expand Up @@ -187,54 +187,8 @@ async def update_shanxi():
logger.error(e)


async def update_jiangxi():
url = f"http://www.jxqingtuan.cn/pub/pub/vol/volClass/index?userId={random.randint(4363000, 4364000)}&&page=1&pageSize=100"
headers.update({
'Cookie': 'JSESSIONID=' + secrets.token_urlsafe(40),
'Host': 'www.jxqingtuan.cn',
'Origin': 'http://www.jxqingtuan.cn',
'Referer': 'http://www.jxqingtuan.cn/html/h5_index.html?&accessToken=' + ''.join(
random.sample(string.ascii_letters + string.digits, 28)),
})
try:
async with AsyncClient(headers=headers) as client:
response = await client.get(url=url)
response.encoding = response.charset_encoding
if response.json().get('code', -1) == 0:
dxxList = response.json().get("list", [])
for item in dxxList:
if await JiangXiDxx.filter(code=item.get("id", -1)).count():
continue
dxxResult = await dxxInfo(
item.get("url").replace("index.html", "m.html").replace("http://", "https://"))
if dxxResult["status"]:
await JiangXiDxx.create(
time=time.time(),
score=item.get("score", 0),
addtime=item.get("addtime", "1970-01-01 00:00:00"),
endtime=item.get("endtime", "1970-01-01 00:00:00"),
code=item.get("id", -2),
starttime=item.get("starttime", "1970-01-01 00:00:00"),
title=dxxResult["catalogue"],
url=item.get("url", "https://h5.cyol.com/special/weixin/sign.json")
)
else:
await JiangXiDxx.create(
time=time.time(),
score=item.get("score", 0),
addtime=item.get("addtime", "1970-01-01 00:00:00"),
endtime=item.get("endtime", "1970-01-01 00:00:00"),
code=item.get("id", -2),
starttime=item.get("starttime", "1970-01-01 00:00:00"),
title=item.get("title", "青年大学习"),
url=item.get("url", "https://h5.cyol.com/special/weixin/sign.json")
)
except Exception as e:
logger.error(e)


async def update_shandong():
headers.update({
headers={
"Host": "qndxx.youth54.cn",
"Connection": "keep-alive",
"Accept": "*/*",
Expand All @@ -245,7 +199,7 @@ async def update_shandong():
"Referer": "http://qndxx.youth54.cn/SmartLA/dxx.w?method=pageSdtwdt",
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7",
})
}
new_version_url = f'http://qndxx.youth54.cn/SmartLA/dxxjfgl.w?method=getNewestVersionInfo'
try:
async with AsyncClient(headers=headers) as client:
Expand Down Expand Up @@ -358,10 +312,6 @@ async def update_data():
logger.error(e)
except Exception as e:
logger.error(e)
# try:
await update_jiangxi()
# except Exception as e:
# logger.error(e)
await update_shandong()
await update_shanxi()

Expand All @@ -373,7 +323,6 @@ async def check_apply():
except ValueError as e:
return
apply_list = await AddUser.filter(status="未通过").values()

for item in apply_list:
result = await User.filter(user_id=item["user_id"], group_id=item["group_id"]).count()
if result:
Expand Down
2 changes: 1 addition & 1 deletion TeenStudy/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ async def distribute_area(user_id: int, area: str, catalogue: Optional[str] = No
if area == "湖北":
return await dxx.hubei(user_id=user_id, catalogue=catalogue)
elif area == "江西":
return await dxx.jiangxi(user_id=user_id, catalogue=catalogue)
return await dxx.jiangxi(user_id=user_id)
elif area == "浙江":
return await dxx.zhejiang(user_id=user_id)
elif area == "上海":
Expand Down
2 changes: 1 addition & 1 deletion TeenStudy/web/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
'''
DRIVER = get_driver()
icon_path = 'https://img1.imgtp.com/2023/10/06/NChUNeiA.png'
icon_path = 'https://www.freeimg.cn/i/2023/12/03/656c227814852.png'


@DRIVER.on_startup
Expand Down
Loading

0 comments on commit fc59635

Please sign in to comment.