kaobian-cli 0.1.0__py3-none-any.whl
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.
- kaobian_cli/__init__.py +8 -0
- kaobian_cli/api.py +77 -0
- kaobian_cli/cli.py +112 -0
- kaobian_cli-0.1.0.dist-info/METADATA +135 -0
- kaobian_cli-0.1.0.dist-info/RECORD +8 -0
- kaobian_cli-0.1.0.dist-info/WHEEL +5 -0
- kaobian_cli-0.1.0.dist-info/entry_points.txt +2 -0
- kaobian_cli-0.1.0.dist-info/top_level.txt +1 -0
kaobian_cli/__init__.py
ADDED
kaobian_cli/api.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"""kaobian CLI —— 数据获取模块。
|
|
2
|
+
|
|
3
|
+
通过 HTTP 从数据服务获取招聘信息。默认直连公开只读数据源;
|
|
4
|
+
后续切换到订阅 API 时,只需修改 base_url 与认证方式,无需改动上层调用。
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import os
|
|
10
|
+
from typing import Any, Optional
|
|
11
|
+
|
|
12
|
+
import requests
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class DataSource:
|
|
16
|
+
"""数据源客户端,负责与后端数据服务交互。"""
|
|
17
|
+
|
|
18
|
+
def __init__(
|
|
19
|
+
self,
|
|
20
|
+
base_url: Optional[str] = None,
|
|
21
|
+
api_key: Optional[str] = None,
|
|
22
|
+
timeout: float = 15.0,
|
|
23
|
+
) -> None:
|
|
24
|
+
# 默认从环境变量读取,便于用户/agent 配置,也可运行时传入。
|
|
25
|
+
self.base_url = (base_url or os.environ.get("KAOBIAN_API_URL") or "").rstrip("/")
|
|
26
|
+
self.api_key = api_key or os.environ.get("KAOBIAN_API_KEY")
|
|
27
|
+
self.timeout = timeout
|
|
28
|
+
|
|
29
|
+
def _headers(self) -> dict[str, str]:
|
|
30
|
+
headers = {"Accept": "application/json"}
|
|
31
|
+
if self.api_key:
|
|
32
|
+
headers["Authorization"] = f"Bearer {self.api_key}"
|
|
33
|
+
return headers
|
|
34
|
+
|
|
35
|
+
def query(
|
|
36
|
+
self,
|
|
37
|
+
keyword: Optional[str] = None,
|
|
38
|
+
job_type: Optional[str] = None,
|
|
39
|
+
region: Optional[str] = None,
|
|
40
|
+
only_open: bool = True,
|
|
41
|
+
limit: int = 50,
|
|
42
|
+
) -> list[dict[str, Any]]:
|
|
43
|
+
"""查询招聘信息。
|
|
44
|
+
|
|
45
|
+
后端接受统一参数:keyword / job_type / region / only_open / limit。
|
|
46
|
+
"""
|
|
47
|
+
if not self.base_url:
|
|
48
|
+
raise RuntimeError(
|
|
49
|
+
"未配置数据服务地址。请设置环境变量 KAOBIAN_API_URL,"
|
|
50
|
+
"或通过 --api-url 参数指定。"
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
params: dict[str, Any] = {"limit": limit}
|
|
54
|
+
if keyword:
|
|
55
|
+
params["keyword"] = keyword
|
|
56
|
+
if job_type:
|
|
57
|
+
params["type"] = job_type
|
|
58
|
+
if region:
|
|
59
|
+
params["region"] = region
|
|
60
|
+
if only_open:
|
|
61
|
+
params["open"] = "true"
|
|
62
|
+
|
|
63
|
+
resp = requests.get(
|
|
64
|
+
f"{self.base_url}/jobs",
|
|
65
|
+
params=params,
|
|
66
|
+
headers=self._headers(),
|
|
67
|
+
timeout=self.timeout,
|
|
68
|
+
)
|
|
69
|
+
resp.raise_for_status()
|
|
70
|
+
data = resp.json()
|
|
71
|
+
|
|
72
|
+
# 兼容两种返回结构:{"data": [...]} 或直接 [...]
|
|
73
|
+
if isinstance(data, dict) and "data" in data:
|
|
74
|
+
return data["data"]
|
|
75
|
+
if isinstance(data, list):
|
|
76
|
+
return data
|
|
77
|
+
raise RuntimeError(f"无法解析数据服务返回:{str(data)[:200]}")
|
kaobian_cli/cli.py
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"""kaobian CLI —— 命令行入口。"""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import json
|
|
7
|
+
import sys
|
|
8
|
+
from typing import Optional
|
|
9
|
+
|
|
10
|
+
from .api import DataSource
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def _fmt_job(job: dict) -> str:
|
|
14
|
+
title = job.get("title", "")
|
|
15
|
+
org = job.get("organization", "")
|
|
16
|
+
jtype = job.get("job_type", "")
|
|
17
|
+
region = job.get("region", "")
|
|
18
|
+
start = job.get("start_date", "")
|
|
19
|
+
end = job.get("end_date", "")
|
|
20
|
+
reliability = job.get("reliability", "")
|
|
21
|
+
headcount = job.get("headcount", "")
|
|
22
|
+
url = job.get("source_url", "")
|
|
23
|
+
|
|
24
|
+
parts = [f"• {title}"]
|
|
25
|
+
if org:
|
|
26
|
+
parts.append(f" 单位:{org}")
|
|
27
|
+
meta = []
|
|
28
|
+
if jtype:
|
|
29
|
+
meta.append(jtype)
|
|
30
|
+
if region:
|
|
31
|
+
meta.append(region)
|
|
32
|
+
if headcount:
|
|
33
|
+
meta.append(f"招{headcount}")
|
|
34
|
+
if reliability:
|
|
35
|
+
meta.append(f"靠谱度:{reliability}")
|
|
36
|
+
if meta:
|
|
37
|
+
parts.append(f" 标签:{' / '.join(meta)}")
|
|
38
|
+
if start or end:
|
|
39
|
+
parts.append(f" 报名:{start or '?'} ~ {end or '?'}")
|
|
40
|
+
if url:
|
|
41
|
+
parts.append(f" 链接:{url}")
|
|
42
|
+
return "\n".join(parts)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _build_parser() -> argparse.ArgumentParser:
|
|
46
|
+
p = argparse.ArgumentParser(
|
|
47
|
+
prog="kaobian",
|
|
48
|
+
description="查询公务员、事业单位、央国企、教师等稳定工作的公开招聘信息。",
|
|
49
|
+
)
|
|
50
|
+
p.add_argument("keyword", nargs="?", help="关键词(匹配岗位/单位名称)")
|
|
51
|
+
p.add_argument(
|
|
52
|
+
"-t", "--type",
|
|
53
|
+
choices=["公务员", "事业单位", "央国企", "教师", "其他"],
|
|
54
|
+
help="按岗位类型筛选",
|
|
55
|
+
)
|
|
56
|
+
p.add_argument("-r", "--region", help="按地区筛选(如:北京 / 广东 / 全国)")
|
|
57
|
+
p.add_argument(
|
|
58
|
+
"--all",
|
|
59
|
+
action="store_true",
|
|
60
|
+
help="同时显示已截止的岗位(默认只看报名中)",
|
|
61
|
+
)
|
|
62
|
+
p.add_argument(
|
|
63
|
+
"-n", "--limit", type=int, default=20, help="最多显示条数(默认 20)"
|
|
64
|
+
)
|
|
65
|
+
p.add_argument(
|
|
66
|
+
"--json", action="store_true", help="以 JSON 格式输出(便于 agent 程序化调用)"
|
|
67
|
+
)
|
|
68
|
+
p.add_argument(
|
|
69
|
+
"--api-url",
|
|
70
|
+
help="数据服务地址(覆盖 KAOBIAN_API_URL 环境变量)",
|
|
71
|
+
)
|
|
72
|
+
p.add_argument(
|
|
73
|
+
"--api-key",
|
|
74
|
+
help="订阅 API Key(覆盖 KAOBIAN_API_KEY 环境变量)",
|
|
75
|
+
)
|
|
76
|
+
return p
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def main(argv: Optional[list[str]] = None) -> int:
|
|
80
|
+
args = _build_parser().parse_args(argv)
|
|
81
|
+
|
|
82
|
+
source = DataSource(base_url=args.api_url, api_key=args.api_key)
|
|
83
|
+
|
|
84
|
+
try:
|
|
85
|
+
jobs = source.query(
|
|
86
|
+
keyword=args.keyword,
|
|
87
|
+
job_type=args.type,
|
|
88
|
+
region=args.region,
|
|
89
|
+
only_open=not args.all,
|
|
90
|
+
limit=args.limit,
|
|
91
|
+
)
|
|
92
|
+
except Exception as exc: # noqa: BLE001
|
|
93
|
+
print(f"错误:{exc}", file=sys.stderr)
|
|
94
|
+
return 1
|
|
95
|
+
|
|
96
|
+
if args.json:
|
|
97
|
+
print(json.dumps(jobs, ensure_ascii=False, indent=2))
|
|
98
|
+
return 0
|
|
99
|
+
|
|
100
|
+
if not jobs:
|
|
101
|
+
print("未找到符合条件的招聘信息。")
|
|
102
|
+
return 0
|
|
103
|
+
|
|
104
|
+
print(f"共 {len(jobs)} 条:\n")
|
|
105
|
+
for job in jobs:
|
|
106
|
+
print(_fmt_job(job))
|
|
107
|
+
print()
|
|
108
|
+
return 0
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
if __name__ == "__main__":
|
|
112
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: kaobian-cli
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: kaobian —— 查询公务员、事业单位、央国企、教师等稳定工作公开招聘信息的命令行工具
|
|
5
|
+
Author: kaobian
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://www.kaobian.site
|
|
8
|
+
Project-URL: Documentation, https://gitee.com/povichuang/kaobian
|
|
9
|
+
Project-URL: Source, https://gitee.com/povichuang/kaobian
|
|
10
|
+
Project-URL: Issues, https://gitee.com/povichuang/kaobian/issues
|
|
11
|
+
Keywords: 招聘,公务员,事业单位,央国企,教师,CLI,考编,kaobian,job,recruitment
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Intended Audience :: End Users/Desktop
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Classifier: Topic :: Utilities
|
|
24
|
+
Requires-Python: >=3.8
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
Requires-Dist: requests>=2.25
|
|
27
|
+
|
|
28
|
+
# kaobian
|
|
29
|
+
|
|
30
|
+
查询**公务员、事业单位、央国企、教师**等稳定工作公开招聘信息的命令行工具(CLI)。
|
|
31
|
+
|
|
32
|
+
为 AI Agent 与开发者设计:一条命令即可获取结构化的招聘信息,便于在脚本、Agent 工作流中直接调用。
|
|
33
|
+
|
|
34
|
+
> 🌐 在线网页版:[https://www.kaobian.site](https://www.kaobian.site)
|
|
35
|
+
|
|
36
|
+
## 特性
|
|
37
|
+
|
|
38
|
+
- 🎯 覆盖公务员、事业单位、央国企、教师编制等稳定工作招聘
|
|
39
|
+
- 🔎 支持按关键词、类型、地区筛选,默认只看「报名中」
|
|
40
|
+
- 🤖 面向 Agent:支持 `--json` 输出结构化数据,便于程序化调用
|
|
41
|
+
- 📦 一键安装:`pip install`
|
|
42
|
+
- ⚡ 数据来自各官方权威渠道公开发布的公告,结构化整理
|
|
43
|
+
|
|
44
|
+
## 安装
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pip install kaobian-cli
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
安装后即可使用 `kaobian` 命令。
|
|
51
|
+
|
|
52
|
+
## 快速开始
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
# 查询"教师"岗位
|
|
56
|
+
kaobian 教师
|
|
57
|
+
|
|
58
|
+
# 查询广东地区的事业单位
|
|
59
|
+
kaobian -t 事业单位 -r 广东
|
|
60
|
+
|
|
61
|
+
# 查询关键词"公务员",输出 JSON(供 agent 调用)
|
|
62
|
+
kaobian 公务员 --json
|
|
63
|
+
|
|
64
|
+
# 显示已截止的岗位(默认只显示报名中)
|
|
65
|
+
kaobian --all 教师
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## 命令说明
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
usage: kaobian [关键词] [选项]
|
|
72
|
+
|
|
73
|
+
位置参数:
|
|
74
|
+
keyword 关键词(匹配岗位/单位名称)
|
|
75
|
+
|
|
76
|
+
选项:
|
|
77
|
+
-t, --type {公务员,事业单位,央国企,教师,其他}
|
|
78
|
+
按岗位类型筛选
|
|
79
|
+
-r, --region REGION 按地区筛选(如:北京 / 广东 / 全国)
|
|
80
|
+
--all 同时显示已截止的岗位(默认只看报名中)
|
|
81
|
+
-n, --limit N 最多显示条数(默认 20)
|
|
82
|
+
--json 以 JSON 格式输出(便于 agent 程序化调用)
|
|
83
|
+
--api-url URL 数据服务地址(覆盖 KAOBIAN_API_URL 环境变量)
|
|
84
|
+
--api-key KEY 订阅 API Key(覆盖 KAOBIAN_API_KEY 环境变量)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## 配置
|
|
88
|
+
|
|
89
|
+
数据服务地址与订阅凭证通过环境变量配置(也可用命令行参数覆盖):
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
export KAOBIAN_API_URL="https://www.kaobian.site"
|
|
93
|
+
export KAOBIAN_API_KEY="your-subscription-key"
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## 在 Agent 中使用
|
|
97
|
+
|
|
98
|
+
CLI 支持 `--json` 输出,可直接被 Agent 的工具调用解析:
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
kaobian -t 教师 -r 浙江 --json
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
返回结构:
|
|
105
|
+
|
|
106
|
+
```json
|
|
107
|
+
[
|
|
108
|
+
{
|
|
109
|
+
"title": "岗位名称",
|
|
110
|
+
"organization": "招聘单位",
|
|
111
|
+
"job_type": "教师",
|
|
112
|
+
"region": "浙江",
|
|
113
|
+
"start_date": "2026-12-01",
|
|
114
|
+
"end_date": "2026-12-18",
|
|
115
|
+
"reliability": "高",
|
|
116
|
+
"headcount": "未知",
|
|
117
|
+
"source_url": "https://..."
|
|
118
|
+
}
|
|
119
|
+
]
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## 数据说明
|
|
123
|
+
|
|
124
|
+
- 数据来源于各官方权威渠道公开发布的招聘公告,仅供参考,请以原始公告为准。
|
|
125
|
+
- 「靠谱程度」字段用于标识信息来源的可靠性,不代表录用概率。
|
|
126
|
+
|
|
127
|
+
## 订阅与使用授权
|
|
128
|
+
|
|
129
|
+
CLI 的**数据服务**提供订阅制访问。免费通道可直接体验基础查询;更高频次、更完整的订阅服务请参考服务提供方的授权说明。
|
|
130
|
+
|
|
131
|
+
> 本仓库仅包含客户端代码与使用文档。数据抓取、数据源配置及后端服务为私有内容,不在本仓库开源。
|
|
132
|
+
|
|
133
|
+
## 许可证
|
|
134
|
+
|
|
135
|
+
[MIT](./LICENSE)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
kaobian_cli/__init__.py,sha256=dXELGj8S3qOXelb8qBrZKylADJ1tC1W01Ja7i3CytfU,176
|
|
2
|
+
kaobian_cli/api.py,sha256=VK-2XlPvSwvrKbTFiBxbmbk-ZW_OZvkhurJwIC7ndw8,2465
|
|
3
|
+
kaobian_cli/cli.py,sha256=wO_AVnM8I4yCNSS9Dvtqnolbdm6EqZpL0kmO1dxwEs8,3175
|
|
4
|
+
kaobian_cli-0.1.0.dist-info/METADATA,sha256=7LYB4sxsy1hSAk4bE49ECjFpm4prq1-uu5t5aNAHF9Q,4315
|
|
5
|
+
kaobian_cli-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
6
|
+
kaobian_cli-0.1.0.dist-info/entry_points.txt,sha256=zSzFQQDtwlwHEkECJtpZZHjPaq6FZTowiH1U-DXuLrY,49
|
|
7
|
+
kaobian_cli-0.1.0.dist-info/top_level.txt,sha256=nnNdr3wVvdR-jE_IB8i3KKBw-8s6HLPUma6HFOoCu4Y,12
|
|
8
|
+
kaobian_cli-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
kaobian_cli
|