py-hikvision-sdk 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. py_hikvision_sdk-0.1.0/.env.example +23 -0
  2. py_hikvision_sdk-0.1.0/.gitee/ISSUE_TEMPLATE.zh-CN.md +13 -0
  3. py_hikvision_sdk-0.1.0/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md +12 -0
  4. py_hikvision_sdk-0.1.0/.gitignore +149 -0
  5. py_hikvision_sdk-0.1.0/.python-version +1 -0
  6. py_hikvision_sdk-0.1.0/LICENSE +21 -0
  7. py_hikvision_sdk-0.1.0/PKG-INFO +53 -0
  8. py_hikvision_sdk-0.1.0/README.en.md +36 -0
  9. py_hikvision_sdk-0.1.0/README.md +39 -0
  10. py_hikvision_sdk-0.1.0/pyproject.toml +177 -0
  11. py_hikvision_sdk-0.1.0/scripts/test_readonly_live.py +160 -0
  12. py_hikvision_sdk-0.1.0/src/py_hikvision_sdk/__init__.py +48 -0
  13. py_hikvision_sdk-0.1.0/src/py_hikvision_sdk/_version.py +6 -0
  14. py_hikvision_sdk-0.1.0/src/py_hikvision_sdk/core/__init__.py +1 -0
  15. py_hikvision_sdk-0.1.0/src/py_hikvision_sdk/core/isc/__init__.py +1 -0
  16. py_hikvision_sdk-0.1.0/src/py_hikvision_sdk/core/isc/base/__init__.py +61 -0
  17. py_hikvision_sdk-0.1.0/src/py_hikvision_sdk/core/isc/base/_config.py +102 -0
  18. py_hikvision_sdk-0.1.0/src/py_hikvision_sdk/core/isc/base/_exceptions.py +150 -0
  19. py_hikvision_sdk-0.1.0/src/py_hikvision_sdk/core/isc/base/_models.py +139 -0
  20. py_hikvision_sdk-0.1.0/src/py_hikvision_sdk/core/isc/base/_signature.py +162 -0
  21. py_hikvision_sdk-0.1.0/src/py_hikvision_sdk/core/isc/base/_sync_api.py +268 -0
  22. py_hikvision_sdk-0.1.0/src/py_hikvision_sdk/core/isc/resource_directory/__init__.py +11 -0
  23. py_hikvision_sdk-0.1.0/src/py_hikvision_sdk/core/isc/resource_directory/_sync_persons.py +99 -0
  24. py_hikvision_sdk-0.1.0/src/py_hikvision_sdk/core/isc/resource_directory/_sync_regions.py +128 -0
  25. py_hikvision_sdk-0.1.0/src/py_hikvision_sdk/core/isc/resource_directory/_sync_resources.py +69 -0
  26. py_hikvision_sdk-0.1.0/src/py_hikvision_sdk/core/isc/vehicle_control/__init__.py +11 -0
  27. py_hikvision_sdk-0.1.0/src/py_hikvision_sdk/core/isc/vehicle_control/_sync_checkpoint.py +363 -0
  28. py_hikvision_sdk-0.1.0/src/py_hikvision_sdk/core/isc/vehicle_control/_sync_parking.py +355 -0
  29. py_hikvision_sdk-0.1.0/src/py_hikvision_sdk/core/isc/vehicle_control/_sync_vehicle.py +303 -0
  30. py_hikvision_sdk-0.1.0/src/py_hikvision_sdk/provider.py +125 -0
  31. py_hikvision_sdk-0.1.0/src/py_hikvision_sdk/py.typed +0 -0
  32. py_hikvision_sdk-0.1.0/tests/conftest.py +78 -0
  33. py_hikvision_sdk-0.1.0/tests/test_integration_destructive.py +207 -0
  34. py_hikvision_sdk-0.1.0/tests/test_integration_readonly.py +193 -0
  35. py_hikvision_sdk-0.1.0/tests/test_signature.py +184 -0
  36. py_hikvision_sdk-0.1.0/uv.lock +822 -0
@@ -0,0 +1,23 @@
1
+ # ============================================================
2
+ # Hikvision iSecure Center 集成测试配置模板
3
+ # ============================================================
4
+ # 使用方法:
5
+ # cp .env.example .env
6
+ # 编辑 .env 填入真实参数后运行:
7
+ # uv run pytest -m readonly # 只跑只读测试(默认)
8
+ # uv run pytest -m destructive # 跑写操作测试(会修改真实数据!)
9
+ # ============================================================
10
+
11
+ # ---- ISC 连接配置(必填)----
12
+ ISC_HOST=192.168.1.100
13
+ ISC_PORT=443
14
+ ISC_AK=your_app_key
15
+ ISC_SK=your_app_secret
16
+ ISC_HTTPS=true
17
+ ISC_VERIFY_SSL=false
18
+ ISC_TIMEOUT=30
19
+
20
+ # ---- 测试执行开关 ----
21
+ # DESTRUCTIVE_TESTS=true 时才会执行标记为 destructive 的写操作测试
22
+ # 默认 false(安全起见)
23
+ ISC_DESTRUCTIVE_TESTS=false
@@ -0,0 +1,13 @@
1
+ ### 该问题是怎么引起的?
2
+
3
+
4
+
5
+ ### 重现步骤
6
+
7
+
8
+
9
+ ### 报错信息
10
+
11
+
12
+
13
+
@@ -0,0 +1,12 @@
1
+ ### 相关的Issue
2
+
3
+
4
+ ### 原因(目的、解决的问题等)
5
+
6
+
7
+ ### 描述(做了什么,变更了什么)
8
+
9
+
10
+ ### 测试用例(新增、改动、可能影响的功能)
11
+
12
+
@@ -0,0 +1,149 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow
98
+ __pypackages__/
99
+
100
+ # Celery stuff
101
+ celerybeat-schedule
102
+ celerybeat.pid
103
+
104
+ # SageMath parsed files
105
+ *.sage.py
106
+
107
+ # Environments
108
+ .env
109
+ .venv
110
+ env/
111
+ venv/
112
+ ENV/
113
+ env.bak/
114
+ venv.bak/
115
+
116
+ # Spyder project settings
117
+ .spyderproject
118
+ .spyproject
119
+
120
+ # Rope project settings
121
+ .ropeproject
122
+
123
+ # mkdocs documentation
124
+ /site
125
+
126
+ # mypy
127
+ .mypy_cache/
128
+ .dmypy.json
129
+ dmypy.json
130
+
131
+ # Pyre type checker
132
+ .pyre/
133
+
134
+ # pytype static type analyzer
135
+ .pytype/
136
+
137
+ # Cython debug symbols
138
+ cython_debug/
139
+
140
+ # uv / tool caches
141
+ .ruff_cache/
142
+ .trae/
143
+ .trae-cn/
144
+ *.pyc
145
+
146
+ # IDE / editor
147
+ .idea/
148
+ .vscode/
149
+ .DS_Store
@@ -0,0 +1 @@
1
+ 3.10
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 郭磊
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,53 @@
1
+ Metadata-Version: 2.5
2
+ Name: py-hikvision-sdk
3
+ Version: 0.1.0
4
+ Summary: Hikvision iSecure Center V1.7.0 OpenAPI Python SDK(官方文档: https://open.hikvision.com/docs/docId?productId=5c67f1e2f05948198c909700)
5
+ Project-URL: Homepage, https://gitee.com/guolei19850528/py_hikvision_sdk
6
+ Project-URL: Repository, https://gitee.com/guolei19850528/py_hikvision_sdk.git
7
+ Project-URL: Issues, https://gitee.com/guolei19850528/py_hikvision_sdk/issues
8
+ Author-email: guolei <174000902@qq.com>
9
+ License-File: LICENSE
10
+ Requires-Python: >=3.10
11
+ Requires-Dist: httpx[http2]>=0.27
12
+ Requires-Dist: pydantic>=2.7
13
+ Description-Content-Type: text/markdown
14
+
15
+ # py_hikvision_sdk
16
+
17
+ #### 介绍
18
+ {**以下是 Gitee 平台说明,您可以替换此简介**
19
+ Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN)。专为开发者提供稳定、高效、安全的云端软件开发协作平台
20
+ 无论是个人、团队、或是企业,都能够用 Gitee 实现代码托管、项目管理、协作开发。企业项目请看 [https://gitee.com/enterprises](https://gitee.com/enterprises)}
21
+
22
+ #### 软件架构
23
+ 软件架构说明
24
+
25
+
26
+ #### 安装教程
27
+
28
+ 1. xxxx
29
+ 2. xxxx
30
+ 3. xxxx
31
+
32
+ #### 使用说明
33
+
34
+ 1. xxxx
35
+ 2. xxxx
36
+ 3. xxxx
37
+
38
+ #### 参与贡献
39
+
40
+ 1. Fork 本仓库
41
+ 2. 新建 Feat_xxx 分支
42
+ 3. 提交代码
43
+ 4. 新建 Pull Request
44
+
45
+
46
+ #### 特技
47
+
48
+ 1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
49
+ 2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com)
50
+ 3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目
51
+ 4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
52
+ 5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
53
+ 6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
@@ -0,0 +1,36 @@
1
+ # py_hikvision_sdk
2
+
3
+ #### Description
4
+ {**When you're done, you can delete the content in this README and update the file with details for others getting started with your repository**}
5
+
6
+ #### Software Architecture
7
+ Software architecture description
8
+
9
+ #### Installation
10
+
11
+ 1. xxxx
12
+ 2. xxxx
13
+ 3. xxxx
14
+
15
+ #### Instructions
16
+
17
+ 1. xxxx
18
+ 2. xxxx
19
+ 3. xxxx
20
+
21
+ #### Contribution
22
+
23
+ 1. Fork the repository
24
+ 2. Create Feat_xxx branch
25
+ 3. Commit your code
26
+ 4. Create Pull Request
27
+
28
+
29
+ #### Gitee Feature
30
+
31
+ 1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md
32
+ 2. Gitee blog [blog.gitee.com](https://blog.gitee.com)
33
+ 3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore)
34
+ 4. The most valuable open source project [GVP](https://gitee.com/gvp)
35
+ 5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help)
36
+ 6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
@@ -0,0 +1,39 @@
1
+ # py_hikvision_sdk
2
+
3
+ #### 介绍
4
+ {**以下是 Gitee 平台说明,您可以替换此简介**
5
+ Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN)。专为开发者提供稳定、高效、安全的云端软件开发协作平台
6
+ 无论是个人、团队、或是企业,都能够用 Gitee 实现代码托管、项目管理、协作开发。企业项目请看 [https://gitee.com/enterprises](https://gitee.com/enterprises)}
7
+
8
+ #### 软件架构
9
+ 软件架构说明
10
+
11
+
12
+ #### 安装教程
13
+
14
+ 1. xxxx
15
+ 2. xxxx
16
+ 3. xxxx
17
+
18
+ #### 使用说明
19
+
20
+ 1. xxxx
21
+ 2. xxxx
22
+ 3. xxxx
23
+
24
+ #### 参与贡献
25
+
26
+ 1. Fork 本仓库
27
+ 2. 新建 Feat_xxx 分支
28
+ 3. 提交代码
29
+ 4. 新建 Pull Request
30
+
31
+
32
+ #### 特技
33
+
34
+ 1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
35
+ 2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com)
36
+ 3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目
37
+ 4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
38
+ 5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
39
+ 6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
@@ -0,0 +1,177 @@
1
+ # ============================================================================
2
+ # Hikvision iSecure Center V1.7.0 Python SDK - 项目配置文件
3
+ # 官方文档: https://open.hikvision.com/docs/docId?productId=5c67f1e2f05948198c909700
4
+ # 工具链: uv + hatchling + ruff + mypy + pytest
5
+ # ============================================================================
6
+
7
+ # —— 构建系统 ——
8
+ # hatchling 是一个轻量级、PEP 517 兼容的构建后端,
9
+ # 支持从源文件动态读取版本号(见下方 [tool.hatch.version])
10
+ [build-system]
11
+ requires = ["hatchling"]
12
+ build-backend = "hatchling.build"
13
+
14
+ # —— 项目元数据 ——
15
+ [project]
16
+ name = "py-hikvision-sdk"
17
+
18
+ # 版本号采用动态读取:构建时从 src/py_hikvision_sdk/_version.py 读取 __version__
19
+ dynamic = ["version"]
20
+
21
+ description = "Hikvision iSecure Center V1.7.0 OpenAPI Python SDK(官方文档: https://open.hikvision.com/docs/docId?productId=5c67f1e2f05948198c909700)"
22
+ readme = "README.md"
23
+
24
+ authors = [
25
+ { name = "guolei", email = "174000902@qq.com" }
26
+ ]
27
+
28
+ requires-python = ">=3.10"
29
+
30
+ # —— 运行时依赖 ——
31
+ dependencies = [
32
+ "httpx[http2]>=0.27",
33
+ "pydantic>=2.7",
34
+ ]
35
+
36
+ # —— 开发依赖 ——
37
+ [dependency-groups]
38
+ dev = [
39
+ "mypy>=1.10",
40
+ "pytest>=8",
41
+ "pytest-asyncio>=0.23",
42
+ "python-dotenv>=1.2.4",
43
+ "ruff>=0.5",
44
+ ]
45
+
46
+ # ---------------------------------------------------------------------------
47
+ # 项目 URL(PyPI / Gitee 展示)
48
+ # ---------------------------------------------------------------------------
49
+ [project.urls]
50
+ Homepage = "https://gitee.com/guolei19850528/py_hikvision_sdk"
51
+ Repository = "https://gitee.com/guolei19850528/py_hikvision_sdk.git"
52
+ Issues = "https://gitee.com/guolei19850528/py_hikvision_sdk/issues"
53
+
54
+
55
+ # ============================================================================
56
+ # hatchling 动态版本 + 打包配置
57
+ # ============================================================================
58
+
59
+ [tool.hatch.version]
60
+ path = "src/py_hikvision_sdk/_version.py"
61
+ expression = "__version__"
62
+
63
+ [tool.hatch.build.targets.wheel]
64
+ packages = ["src/py_hikvision_sdk"]
65
+
66
+ # ============================================================================
67
+ # Ruff 配置(格式化 + Lint)
68
+ # https://docs.astral.sh/ruff/
69
+ # ============================================================================
70
+
71
+ [tool.ruff]
72
+ line-length = 120
73
+ target-version = "py310"
74
+
75
+ [tool.ruff.lint]
76
+ select = [
77
+ "E", # pycodestyle errors
78
+ "F", # pyflakes
79
+ "I", # isort
80
+ "N", # pep8-naming
81
+ "W", # pycodestyle warnings
82
+ "UP", # pyupgrade
83
+ "B", # flake8-bugbear
84
+ "A", # flake8-builtins
85
+ "C4", # flake8-comprehensions
86
+ "SIM", # flake8-simplify
87
+ "PT", # flake8-pytest-style
88
+ ]
89
+
90
+ ignore = [
91
+ "N801", # class name - Provider / API 风格命名可接受
92
+ "N802", # function name - snake_case
93
+ "N803", # argument name
94
+ "N806", # variable name
95
+ "A001", # don't shadow builtins
96
+ "RUF001", # 全角标点
97
+ "RUF002",
98
+ "RUF003",
99
+ "TC001", # 类型导入简化
100
+ "TC002",
101
+ "PLR", # pathlib / refactor 规则过严
102
+ "SIM", # 保持可读性
103
+ "PT011", # pytest.raises 不强制要求 match
104
+ "PT017", # except 块里 assert(pytest.raises 替代)
105
+ "PT018", # 复合 assert 拆分
106
+ "PT019", # fixture 参数可接受
107
+ ]
108
+
109
+ [tool.ruff.lint.isort]
110
+ known-first-party = ["py_hikvision_sdk"]
111
+
112
+ [tool.ruff.lint.pydocstyle]
113
+ convention = "google"
114
+
115
+ [tool.ruff.format]
116
+ quote-style = "double"
117
+ indent-style = "space"
118
+ skip-magic-trailing-comma = false
119
+
120
+ [tool.ruff.lint.per-file-ignores]
121
+ "__init__.py" = ["F401"]
122
+ "conftest.py" = ["E402"]
123
+
124
+ # ============================================================================
125
+ # Mypy 配置(静态类型检查)
126
+ # https://mypy.readthedocs.io/
127
+ # ============================================================================
128
+
129
+ [tool.mypy]
130
+ python_version = "3.10"
131
+ strict = true
132
+ disallow_untyped_defs = true
133
+ disallow_incomplete_defs = true
134
+ check_untyped_defs = true
135
+ warn_return_any = true
136
+ warn_unused_configs = true
137
+ no_implicit_optional = true
138
+ warn_redundant_casts = true
139
+ warn_unused_ignores = true
140
+
141
+ # —— 第三方包跳过 ——
142
+ [[tool.mypy.overrides]]
143
+ module = [
144
+ "pydantic.*",
145
+ "httpx.*",
146
+ "httpcore.*",
147
+ "h11.*",
148
+ "h2.*",
149
+ ]
150
+ ignore_missing_imports = true
151
+
152
+ # 业务子模块:_post_json().data 返回 Any,strict 模式下需要关闭 no-any-return
153
+ [[tool.mypy.overrides]]
154
+ module = [
155
+ "py_hikvision_sdk.core.isc.resource_directory.*",
156
+ "py_hikvision_sdk.core.isc.vehicle_control.*",
157
+ ]
158
+ disable_error_code = ["no-any-return"]
159
+
160
+ [[tool.mypy.overrides]]
161
+ module = ["tests.*", "conftest"]
162
+ disallow_untyped_defs = false
163
+ no_implicit_optional = false
164
+ ignore_missing_imports = true
165
+
166
+ # ============================================================================
167
+ # Pytest 配置
168
+ # ============================================================================
169
+
170
+ [tool.pytest.ini_options]
171
+ asyncio_mode = "auto"
172
+ testpaths = ["tests"]
173
+ markers = [
174
+ "readonly: 只读集成测试(默认执行)",
175
+ "destructive: 写操作集成测试(需显式 -m destructive + ISC_DESTRUCTIVE_TESTS=true)",
176
+ ]
177
+ addopts = "-ra --strict-markers"
@@ -0,0 +1,160 @@
1
+ """只读集成测试脚本 - 打印每个接口的完整返回值。
2
+
3
+ 使用:
4
+ 1) cp .env.example .env # 填入真实 ISC 参数
5
+ 2) uv run python scripts/test_readonly_live.py
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import json
11
+ import sys
12
+ import traceback
13
+
14
+ from dotenv import load_dotenv
15
+
16
+ from py_hikvision_sdk import ISCSyncAPIProvider, ISCSyncConfig
17
+
18
+
19
+ def _print_section(title: str) -> None:
20
+ print("\n" + "=" * 72)
21
+ print(f" {title}")
22
+ print("=" * 72)
23
+
24
+
25
+ def _print_result(name: str, result) -> None:
26
+ print(f"\n▶ {name}")
27
+ try:
28
+ body = json.dumps(result, ensure_ascii=False, indent=2, default=str)
29
+ # 截断过长输出
30
+ if len(body) > 2000:
31
+ body = body[:2000] + "\n... (truncated)"
32
+ print(body)
33
+ except Exception:
34
+ print(repr(result))
35
+
36
+
37
+ def _print_error(name: str, exc: Exception) -> None:
38
+ print(f"\n✗ {name} 出错: {type(exc).__name__}: {exc}")
39
+ # 只打印 2 行 traceback
40
+ tb = traceback.format_exc().strip().split("\n")
41
+ for line in tb[-3:]:
42
+ print(f" {line}")
43
+
44
+
45
+ def main() -> int:
46
+ # 1) 加载 .env
47
+ load_dotenv()
48
+
49
+ import os
50
+
51
+ host = os.environ.get("ISC_HOST")
52
+ port = os.environ.get("ISC_PORT")
53
+ ak = os.environ.get("ISC_AK")
54
+ sk = os.environ.get("ISC_SK")
55
+
56
+ if not all([host, port, ak, sk]):
57
+ print("❌ 请先创建 .env 文件并填入 ISC_HOST / ISC_PORT / ISC_AK / ISC_SK")
58
+ print(" 参考: cp .env.example .env")
59
+ return 1
60
+
61
+ https = os.environ.get("ISC_HTTPS", "true").lower() == "true"
62
+ verify_ssl = os.environ.get("ISC_VERIFY_SSL", "false").lower() == "true"
63
+ timeout = int(os.environ.get("ISC_TIMEOUT", "30"))
64
+
65
+ # 2) 构造 Provider
66
+ cfg = ISCSyncConfig(
67
+ host=host,
68
+ port=int(port),
69
+ ak=ak,
70
+ sk=sk,
71
+ https=https,
72
+ verify_ssl=verify_ssl,
73
+ timeout=timeout,
74
+ )
75
+ provider = ISCSyncAPIProvider(config=cfg)
76
+
77
+ # 3) 逐个接口测试
78
+ total = 0
79
+ passed = 0
80
+ failed = 0
81
+
82
+ def run_test(name: str, func):
83
+ nonlocal total, passed, failed
84
+ total += 1
85
+ try:
86
+ result = func()
87
+ _print_result(name, result)
88
+ passed += 1
89
+ print(f" ✅ OK")
90
+ except Exception as e:
91
+ _print_error(name, e)
92
+ failed += 1
93
+
94
+ try:
95
+ _print_section("📡 连接信息")
96
+ print(f" base_url : {cfg.base_url}")
97
+ print(f" ak : {cfg.ak[:4]}****")
98
+ print(f" timeout : {cfg.timeout}s")
99
+ print()
100
+
101
+ # ==================================================================
102
+ # 区域
103
+ # ==================================================================
104
+ _print_section("1️⃣ 区域查询")
105
+ run_test("get_root_region", lambda: provider.isc_sync_regions_api.get_root_region())
106
+ run_test("query_regions_v2", lambda: provider.isc_sync_regions_api.query_regions(page_no=1, page_size=5))
107
+
108
+ # ==================================================================
109
+ # 人员
110
+ # ==================================================================
111
+ _print_section("2️⃣ 人员查询")
112
+ run_test("query_persons", lambda: provider.isc_sync_persons_api.query_persons(page_no=1, page_size=5))
113
+ run_test("query_orgs", lambda: provider.isc_sync_persons_api.query_orgs(page_no=1, page_size=5))
114
+
115
+ # ==================================================================
116
+ # 资源
117
+ # ==================================================================
118
+ _print_section("3️⃣ 资源查询")
119
+ run_test("query_resources", lambda: provider.isc_sync_resources_api.query_resources(resource_type="camera", page_no=1, page_size=5))
120
+
121
+ # ==================================================================
122
+ # 车辆
123
+ # ==================================================================
124
+ _print_section("4️⃣ 车辆查询")
125
+ run_test("query_vehicles_v2", lambda: provider.isc_sync_vehicle_api.query_vehicles_v2(page_no=1, page_size=5))
126
+ run_test("query_park_list", lambda: provider.isc_sync_vehicle_api.query_park_list())
127
+ run_test("query_park_nodes", lambda: provider.isc_sync_vehicle_api.query_park_nodes(page_no=1, page_size=5))
128
+
129
+ # ==================================================================
130
+ # 停车
131
+ # ==================================================================
132
+ _print_section("5️⃣ 停车查询")
133
+ run_test("query_cross_records", lambda: provider.isc_sync_parking_api.query_cross_records(page_no=1, page_size=5))
134
+ run_test("query_park_time_range", lambda: provider.isc_sync_parking_api.query_park_time_range(page_no=1, page_size=5))
135
+
136
+ # ==================================================================
137
+ # 卡口
138
+ # ==================================================================
139
+ _print_section("6️⃣ 卡口查询")
140
+ run_test("query_whitelists", lambda: provider.isc_sync_checkpoint_api.query_whitelists(page_no=1, page_size=5))
141
+ run_test("query_blacklists", lambda: provider.isc_sync_checkpoint_api.query_blacklists(page_no=1, page_size=5))
142
+ run_test("query_illegal_events", lambda: provider.isc_sync_checkpoint_api.query_illegal_events(page_no=1, page_size=5))
143
+
144
+ # ==================================================================
145
+ # 汇总
146
+ # ==================================================================
147
+ _print_section("📊 测试汇总")
148
+ print(f" 总计 : {total}")
149
+ print(f" ✅ 成功 : {passed}")
150
+ print(f" ✗ 失败 : {failed}")
151
+ print()
152
+
153
+ finally:
154
+ provider.close()
155
+
156
+ return 0 if failed == 0 else 2
157
+
158
+
159
+ if __name__ == "__main__":
160
+ sys.exit(main())