Skip to content

Commit

Permalink
增加黑龙江地区
Browse files Browse the repository at this point in the history
  • Loading branch information
ZM25XC committed May 20, 2023
1 parent 9aa24ce commit d2b5962
Show file tree
Hide file tree
Showing 8 changed files with 376 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish_teenstudy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Build package
run: |
python -m build
twine check --strict dist/*
twine upload dist/*
- name: Publish package
uses: pypa/gh-action-pypi-publish@master
with:
Expand Down
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
|青春山东|支持|需要自行抓包|
|重庆共青团|支持|需要自行抓包|
|吉青飞扬|支持|需要自行抓包|
|黑龙江共青团|支持|需要自行抓包,该地区上线测试中|
|天府新青年|支持|不进入公众号token时效大于1周|
|河南共青团|不支持|cookie时效小于1周|
|黑龙江共青团|待开发||
|广西青年圈|待开发||
|青春湖南|待开发||
|甘肃青年|待开发||
Expand Down Expand Up @@ -80,8 +80,8 @@
<details>
<summary>第二种方式(二选一)</summary>

1、使用`pip install TeenStudy`来进行安装,使用`pip install TeenStudy -U`进行更新
2、使用`nb plugin install TeenStudy`来进行安装,使用`nb plugin install TeenStudy -U`进行更新
- 使用`pip install TeenStudy`来进行安装,使用`pip install TeenStudy -U`进行更新
- 使用`nb plugin install TeenStudy`来进行安装,使用`nb plugin install TeenStudy -U`进行更新

</details>

Expand Down Expand Up @@ -160,10 +160,17 @@

## 更新日志

### 2023/05/11
### 2023/05/21

- 增加黑龙江地区,需要自行抓包,该地区上线测试中,请积极提issue反馈
- 下版本为大版本更新,将添加新功能,优化功能,请积极提issue反馈或加交流群反馈

<details>
<summary>2023/05/11</summary>

- 增加广东地区,无需抓包[#13](https://github.com/ZM25XC/TeenStudy/issues/13),感谢[@neal240](https://github.com/neal240)提供账号测试

</details>

<details>
<summary>2023/05/06</summary>
Expand Down
68 changes: 68 additions & 0 deletions TeenStudy/utils/dxx.py
Original file line number Diff line number Diff line change
Expand Up @@ -1075,3 +1075,71 @@ async def guangdong(user_id: int) -> dict:
"status": 500,
"msg": "提交失败!"
}

async def heilongjiang(user_id: int) -> dict:
"""
黑龙江共青团
:param user_id:用户ID
:return:
"""
result = await User.filter(user_id=user_id).values()
if not result:
return {
"status": 500,
"msg": "用户数据不存在!"
}
else:
cookie = result[0]["cookie"]
answer = await Answer.all().order_by("time").values()
headers = {
"Host": "tsw.ithyxy.com",
"Connection": "keep-alive",
"Accept": "application/json, text/plain, */*",
"User-Agent": "Mozilla/5.0 (Linux; Android 12; M2007J3SC Build/SKQ1.220303.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/86.0.4240.99 XWEB/3262 MMWEBSDK/20220204 Mobile Safari/537.36 MMWEBID/6170 MicroMessenger/8.0.20.2100(0x28001438) Process/toolsmp WeChat/arm32 Weixin NetType/WIFI Language/zh_CN ABI/arm64",
"X-Requested-With": "com.tencent.mm",
"Referer": "http://tsw.ithyxy.com/login",
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7",
"Cookie": cookie
}
try:
learn_url = "http://tsw.ithyxy.com/h5/learn/home"
async with AsyncClient(headers=headers, timeout=5, max_redirects=5) as client:
response = await client.get(url=learn_url)
response.encoding = response.charset_encoding
if response.status_code == 200 and response.json()["code"] == 200:
learn_id = response.json()["data"]["id"]
commit_url = f"http://tsw.ithyxy.com/h5/learn/enter?id={learn_id}"
async with AsyncClient(headers=headers, timeout=5, max_redirects=5) as client:
response = await client.get(url=commit_url)
response.encoding = response.charset_encoding
if response.status_code == 200 and response.json()["code"] == 200:
await User.filter(user_id=user_id).update(
commit_time=time.time(),
catalogue=answer[-1]["catalogue"]
)
await commit(user_id=user_id, catalogue=answer[-1]["catalogue"], status=True)
return {
"status": 0,
"catalogue": answer[-1]["catalogue"],
"msg": "提交成功!"
}
else:
await commit(user_id=user_id, catalogue=answer[-1]["catalogue"], status=False)
return {
"status": 500,
"msg": "提交失败,cookie失效!"
}
else:
await commit(user_id=user_id, catalogue=answer[-1]["catalogue"], status=False)
return {
"status": 500,
"msg": "提交失败,cookie失效!"
}
except Exception as e:
logger.error(e)
await commit(user_id=user_id, catalogue=answer[-1]["catalogue"], status=False)
return {
"status": 500,
"msg": "提交失败!"
}
13 changes: 13 additions & 0 deletions TeenStudy/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,15 @@ class UserModel(BaseModel):
"status": True,
"catalogue": None
},
{
"area": "黑龙江",
"host": "tsw.ithyxy.com",
"referer": None,
"origin": "http://tsw.ithyxy.com/login",
"url": "http://tsw.ithyxy.com/h5/learn/home",
"status": True,
"catalogue": None
},
]
RESOURCE = [
{
Expand Down Expand Up @@ -517,6 +526,8 @@ async def distribute_area(user_id: int, area: str) -> dict:
return await dxx.jilin(user_id=user_id)
elif area == "广东":
return await dxx.guangdong(user_id=user_id)
elif area == "黑龙江":
return await dxx.heilongjiang(user_id=user_id)
else:
return {
"status": 404,
Expand Down Expand Up @@ -544,6 +555,8 @@ async def distribute_area_url(province: str, user_id: int, group_id: int) -> dic
province = "jilin"
elif province == "广东":
province="guangdong"
elif province == "黑龙江":
province = "heilongjiang"
data = f"http://{config['DXX_IP']}:{config['DXX_PORT']}/TeenStudy/api/{province}?user_id={user_id}&group_id={group_id}"
img = qrcode.make(data=data)
buf = BytesIO()
Expand Down
141 changes: 140 additions & 1 deletion TeenStudy/web/api/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from httpx import AsyncClient

from ..pages.add import hubei_page, jiangxi_page, jiangsu_page, anhui_page, sichuan_page, shandong_page, \
chongqing_page, jilin_page, guangdong_page
chongqing_page, jilin_page, guangdong_page,heilongjiang_page
from ..utils.add import write_to_database
from ...models.accuont import User, AddUser
from ...models.dxx import JiangXi
Expand Down Expand Up @@ -814,3 +814,142 @@ async def guangdong(user_id: int, group_id: int):
return RedirectResponse(
url="/TeenStudy/login"
)


@route.post("/heilongjiang/add", response_class=HTMLResponse)
async def heilongjiang_add(data: dict) -> JSONResponse:
user_id = data["user_id"]
if await User.filter(user_id=user_id).count():
return JSONResponse({
"status": 500,
"msg": "添加失败!,用户信息存在!"
})
else:
try:
cookie = data["cookie"]
url = "http://tsw.ithyxy.com/h5/auth/info"
headers = {
"Host": "tsw.ithyxy.com",
"Connection": "keep-alive",
"Accept": "application/json, text/plain, */*",
"User-Agent": "Mozilla/5.0 (Linux; Android 12; M2007J3SC Build/SKQ1.220303.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/86.0.4240.99 XWEB/3262 MMWEBSDK/20220204 Mobile Safari/537.36 MMWEBID/6170 MicroMessenger/8.0.20.2100(0x28001438) Process/toolsmp WeChat/arm32 Weixin NetType/WIFI Language/zh_CN ABI/arm64",
"X-Requested-With": "com.tencent.mm",
"Referer": "http://tsw.ithyxy.com/login",
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7",
"Cookie": cookie
}
async with AsyncClient(headers=headers) as client:
response = await client.get(url, headers=headers)
response.encoding = response.charset_encoding
if response.status_code == 200 and response.json()["code"] == 200:
result = response.json()
data["name"] = result["data"]["name"]
data["gender"] = result["data"]["sex"]
data["mobile"] = result["data"]["phone"]
class_url = "http://tsw.ithyxy.com/h5/auth/class?id=0"
async with AsyncClient(headers=headers) as client:
response = await client.get(url=class_url)
response.encoding = response.charset_encoding
if response.status_code == 200 and response.json()["code"] == 200:
university_list = response.json()["data"]
for x, item in enumerate(result["data"]["path"]):
if x == 0:
for item2 in university_list:
if item == item2["id"]:
data["university_type"] = item2["name"]
break
elif x == 1:
async with AsyncClient(headers=headers) as client:
response = await client.get(
url=f"http://tsw.ithyxy.com/h5/auth/class?id={result['data']['path'][0]}")
response.encoding = response.charset_encoding
if response.status_code == 200 and response.json()["code"] == 200:
university_list = response.json()["data"]
for item2 in university_list:
if item == item2["id"]:
data["university"] = item2["name"]
data["university_id"] = item
break
else:
data["university"] = item
continue
elif x == 2:
async with AsyncClient(headers=headers) as client:
response = await client.get(
url=f"http://tsw.ithyxy.com/h5/auth/class?id={result['data']['path'][1]}")
response.encoding = response.charset_encoding
if response.status_code == 200 and response.json()["code"] == 200:
university_list = response.json()["data"]
for item2 in university_list:
if item == item2["id"]:
data["college"] = item2["name"]
data["college_id"] = item
break
else:
data["college"] = item
continue
elif x == 3:
async with AsyncClient(headers=headers) as client:
response = await client.get(
url=f"http://tsw.ithyxy.com/h5/auth/class?id={result['data']['path'][2]}")
response.encoding = response.charset_encoding
if response.status_code == 200 and response.json()["code"] == 200:
university_list = response.json()["data"]
for item2 in university_list:
if item == item2["id"]:
data["organization"] = item2["name"]
data["organization_id"] = item
break
else:
data["organization"] = item
continue
status = await write_to_database(data=data)
if status:
return JSONResponse(
{
"status": 0,
"msg": "添加成功!"
}
)
else:
return JSONResponse({
"status": 500,
"msg": "添加失败!"
})
else:
data["university"] = result["data"]["path"][0]
data["college"] = result["data"]["path"][1]
status = await write_to_database(data=data)
if status:
return JSONResponse(
{
"status": 0,
"msg": "添加成功!"
}
)
else:
return JSONResponse({
"status": 500,
"msg": "添加失败!"
})
else:
return JSONResponse({"status": 500, "msg": "添加失败!"})
except Exception as e:
return JSONResponse({
"status": 500,
"msg": f"添加失败,{e}"
})


@route.get("/heilongjiang", response_class=HTMLResponse)
async def heilongjiang(user_id: int, group_id: int):
result = await AddUser.filter(user_id=user_id, group_id=group_id, status="未通过").count()
if result:
return heilongjiang_page.render(
site_title='黑龙江共青团 | TeenStudy',
site_icon="https://i.328888.xyz/2023/02/23/xIh5k.png"
)
return RedirectResponse(
url="/TeenStudy/login"
)
63 changes: 63 additions & 0 deletions TeenStudy/web/pages/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -938,3 +938,66 @@
)

guangdong_page = Page(title='添加大学习', body=[logo, Divider(), guangdong_table, footer])

heilongjiang_table = Form(
title="黑龙江共青团",
mode=DisplayModeEnum.horizontal,
api="post:/TeenStudy/api/heilongjiang/add",
redirect="/TeenStudy/login",
body=[
InputText(
label="用户ID",
description="用户ID,为用户QQ号,无需填写",
name="user_id",
value="${user_id}",
disabled=True
),
InputText(
label="通知群ID",
description="通知群号,无需填写",
name="group_id",
value="${group_id}",
disabled=True
),
InputText(
label="地区",
description="所处省份",
name="area",
value="黑龙江",
disabled=True
),
InputText(
label="登录密码",
type='input-password',
description="可不填,默认为用户ID",
name="password",
inline=False,
required=False,
value="",
clearable=True,
maxLength=16
),
InputText(
label="姓名",
description="对应黑龙江共青团个人信息页 您的姓名",
name="name",
inline=False,
required=True,
value="",
clearable=True,
maxLength=8
),
InputText(
label="cookie",
description="自行抓包获取,结构为:SESSION=Y2RhZThmZTUtM2QzXXXXXXXXWIxMDktZjI5ZDk2NzNmOTY5",
name="cookie",
inline=False,
required=True,
value="",
clearable=True,
)

]
)

heilongjiang_page = Page(title='添加大学习', body=[logo, Divider(), heilongjiang_table, footer])
Loading

0 comments on commit d2b5962

Please sign in to comment.