Skip to content

Commit

Permalink
Merge pull request #43 from FarmerChillax/add-type
Browse files Browse the repository at this point in the history
添加 cookies 的登录方式,并完善 typo
  • Loading branch information
FarmerChillax authored Apr 10, 2024
2 parents cf8a7f2 + 3cc362d commit f4e50af
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 12 deletions.
18 changes: 10 additions & 8 deletions docs/接口方法/index.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# 概览


| Api | Description | Argument |
| :-------------------------------- | :-------------------------- | :---------------- |
| [user_login](./user_login.md) | 登陆函数 | account, password |
| [get_schedule](./get_schedule.md) | 课表查询 | year, term |
| [get_score](./get_score.md) | 成绩查询 | year, term |
| [get_info](./get_info.md) | 获取个人信息 | None |
| [refresh_info](./others.md) | 刷新个人信息 | None |
| [check_session](./others.md) | 检查session并其失效后重登录 | None |
| Api | Description | Argument |
| :----------------------------------------- | :-------------------------------------------------------------- | :---------------- |
| [user_login](./user_login.md) | 登陆函数 | account, password |
| [user_login_with_cookies](./user_login.md) | cookie 登陆函数 | cookies, account |
| [init_dev_user](./user_login.md) | 开发测试函数,主要用于开发者调试使用,传入 cookie,无需频繁登录 | cookies |
| [get_schedule](./get_schedule.md) | 课表查询 | year, term |
| [get_score](./get_score.md) | 成绩查询 | year, term |
| [get_info](./get_info.md) | 获取个人信息 | None |
| [refresh_info](./others.md) | 刷新个人信息 | None |
| [check_session](./others.md) | 检查session并其失效后重登录 | None |

5 changes: 4 additions & 1 deletion docs/接口方法/user_login.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ Gdust = SchoolClient("172.16.254.1")

# 实例化用户
user:UserClient = Gdust.user_login("account", "password")
```
```

## 其他登录方式
更多登录 demo 详见仓库 [examples](https://github.com/FarmerChillax/new-school-sdk/tree/master/examples) 目录
29 changes: 29 additions & 0 deletions examples/cookie_login_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
'''
:file: dev_example.py
:author: -Farmer
:url: https://blog.farmer233.top
:date: 2022/01/06 20:34:12
'''
from school_sdk import SchoolClient
from school_sdk.client import UserClient

# 实例化学校
Gdust = SchoolClient("172.16.254.1", port=2333)

# 实例化用户
cookies_str = "<Your cookies string>" # e.g JSESSIONID=E738AE92B3CF133171F5B8E3E4643A5E
user: UserClient = Gdust.user_login_with_cookies(cookies_str, account="2018xxxxxx")

# 获取课表
course = user.get_schedule(year=2020, term=2)
print(course)

# 获取成绩, 2020-2021学年第一学期的成绩
score = user.get_score(year=2020, term=1)
print(score)

# 获取个人信息
info = user.get_info()
print(info)

3 changes: 2 additions & 1 deletion school_sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
:date: 2021/09/02 19:18:47
'''

from .client import SchoolClient, UserClient
from .client import SchoolClient, UserClient
from .type import CAPTCHA, KCAPTCHA
16 changes: 16 additions & 0 deletions school_sdk/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
from school_sdk.client.base import BaseUserClient


CAPTCHA: str = 'captcha'
KCAPTCHA: str = 'kap'

class SchoolClient():

def __init__(self, host, port: int = 80, ssl: bool = False, name=None, exist_verify: bool = False,
Expand Down Expand Up @@ -68,6 +71,19 @@ def user_login(self, account: str, password: str, **kwargs):
user = UserClient(self, account=account, password=password, **kwargs)
return user.login()

def user_login_with_cookies(self, cookies: str, account: str = "cookie login account", **kwargs):
"""使用cookies登录
该方法因缺失帐号密码,因此无法刷新session,需要手动刷新
传参中的 account 主要用于标识当前登录用户、记录日志信息等用途,不会用于登录
Args:
cookies (str): Cookies字符串
account (str, optional): 账号. Defaults to "cookie login account".
"""

user = UserClient(self, account=account, password="cookies login password", **kwargs)
return user.get_dev_user(cookies)

def init_dev_user(self, cookies: str = None):
dev_user = UserClient(self, account="dev account",
password="dev password")
Expand Down
9 changes: 9 additions & 0 deletions school_sdk/type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# -*- coding: utf-8 -*-
'''
:file: __init__.py
:author: -Farmer
:url: https://blog.farmer233.top
:date: 2024/01/12 19:18:47
'''

from .client import CAPTCHA, KCAPTCHA
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
setup(
name="school-sdk",
author="farmer.chillax",
version="1.5.0",
version="1.6.0",
license='MIT',
author_email="farmer-chong@qq.com",
description="zf School SDK for Python",
Expand Down
2 changes: 1 addition & 1 deletion zf-setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
setup(
name="zf-school-sdk",
author="farmer.chillax",
version="1.5.0",
version="1.6.0",
license='MIT',
author_email="farmer-chong@qq.com",
description="zf School SDK for Python",
Expand Down

0 comments on commit f4e50af

Please sign in to comment.