From 4e5f2b0531f22f3cc4be6eea6109035d5a2a9ea2 Mon Sep 17 00:00:00 2001 From: FarmerChillax Date: Mon, 8 Jan 2024 09:52:23 +0800 Subject: [PATCH 1/5] feat: add captcha type --- school_sdk/__init__.py | 3 ++- school_sdk/client/__init__.py | 3 +++ school_sdk/type.py | 9 +++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 school_sdk/type.py diff --git a/school_sdk/__init__.py b/school_sdk/__init__.py index 0bde1d3..01e06b0 100644 --- a/school_sdk/__init__.py +++ b/school_sdk/__init__.py @@ -6,4 +6,5 @@ :date: 2021/09/02 19:18:47 ''' -from .client import SchoolClient, UserClient \ No newline at end of file +from .client import SchoolClient, UserClient +from .type import CAPTCHA, KCAPTCHA diff --git a/school_sdk/client/__init__.py b/school_sdk/client/__init__.py index 3529c7d..9cb09f2 100644 --- a/school_sdk/client/__init__.py +++ b/school_sdk/client/__init__.py @@ -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, diff --git a/school_sdk/type.py b/school_sdk/type.py new file mode 100644 index 0000000..f8702ed --- /dev/null +++ b/school_sdk/type.py @@ -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 From fee541d1efc14a7bb89a568c8d38b09d4b8961bb Mon Sep 17 00:00:00 2001 From: FarmerChillax Date: Wed, 10 Apr 2024 17:46:29 +0800 Subject: [PATCH 2/5] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=20cookies=20?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- school_sdk/client/__init__.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/school_sdk/client/__init__.py b/school_sdk/client/__init__.py index 9cb09f2..94d9d34 100644 --- a/school_sdk/client/__init__.py +++ b/school_sdk/client/__init__.py @@ -71,6 +71,18 @@ 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", password: str = "cookie login password", **kwargs): + """使用cookies登录 + + Args: + cookies (str): Cookies字符串 + account (str, optional): 账号. Defaults to "cookie login account". + password (str, optional): 密码. Defaults to "cookie login password". + """ + + user = UserClient(self, account=account, password=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") From a23a100ff27232c2e9e1f1b96d86e30ce3a9094b Mon Sep 17 00:00:00 2001 From: FarmerChillax Date: Wed, 10 Apr 2024 17:52:10 +0800 Subject: [PATCH 3/5] feat: add cookies login --- examples/cookie_login_example.py | 29 +++++++++++++++++++++++++++++ school_sdk/client/__init__.py | 7 ++++--- 2 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 examples/cookie_login_example.py diff --git a/examples/cookie_login_example.py b/examples/cookie_login_example.py new file mode 100644 index 0000000..9b00b2e --- /dev/null +++ b/examples/cookie_login_example.py @@ -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 = "" # 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) + diff --git a/school_sdk/client/__init__.py b/school_sdk/client/__init__.py index 94d9d34..488e683 100644 --- a/school_sdk/client/__init__.py +++ b/school_sdk/client/__init__.py @@ -71,16 +71,17 @@ 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", password: str = "cookie login password", **kwargs): + 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". - password (str, optional): 密码. Defaults to "cookie login password". """ - user = UserClient(self, account=account, password=password, **kwargs) + user = UserClient(self, account=account, password="cookies login password", **kwargs) return user.get_dev_user(cookies) def init_dev_user(self, cookies: str = None): From 3fcfcd31a9528ae66fccaed6a09be3754c76dfad Mon Sep 17 00:00:00 2001 From: FarmerChillax Date: Wed, 10 Apr 2024 17:58:17 +0800 Subject: [PATCH 4/5] =?UTF-8?q?docs:=20=E5=AE=8C=E5=96=84=E6=96=87?= =?UTF-8?q?=E6=A1=A3=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../index.md" | 18 ++++++++++-------- .../user_login.md" | 5 ++++- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git "a/docs/\346\216\245\345\217\243\346\226\271\346\263\225/index.md" "b/docs/\346\216\245\345\217\243\346\226\271\346\263\225/index.md" index e833151..615489f 100644 --- "a/docs/\346\216\245\345\217\243\346\226\271\346\263\225/index.md" +++ "b/docs/\346\216\245\345\217\243\346\226\271\346\263\225/index.md" @@ -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 | diff --git "a/docs/\346\216\245\345\217\243\346\226\271\346\263\225/user_login.md" "b/docs/\346\216\245\345\217\243\346\226\271\346\263\225/user_login.md" index 7ceb6b2..046586e 100644 --- "a/docs/\346\216\245\345\217\243\346\226\271\346\263\225/user_login.md" +++ "b/docs/\346\216\245\345\217\243\346\226\271\346\263\225/user_login.md" @@ -15,4 +15,7 @@ Gdust = SchoolClient("172.16.254.1") # 实例化用户 user:UserClient = Gdust.user_login("account", "password") -``` \ No newline at end of file +``` + +## 其他登录方式 +更多登录 demo 详见仓库 [examples](https://github.com/FarmerChillax/new-school-sdk/tree/master/examples) 目录 \ No newline at end of file From 3cc362d42d5cef54c5369a1fb86bc019aa55e2ab Mon Sep 17 00:00:00 2001 From: FarmerChillax Date: Wed, 10 Apr 2024 18:11:02 +0800 Subject: [PATCH 5/5] build: update version --- setup.py | 2 +- zf-setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 120ba4f..1704d5a 100644 --- a/setup.py +++ b/setup.py @@ -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", diff --git a/zf-setup.py b/zf-setup.py index c0f4634..528a486 100644 --- a/zf-setup.py +++ b/zf-setup.py @@ -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",