This commit is contained in:
2026-08-21 23:21:00 +08:00
parent 487fb84aac
commit 3abe7c32f0
9 changed files with 543 additions and 0 deletions
+85
View File
@@ -0,0 +1,85 @@
"""发送全部类型的 Bark 通知,用于在手机上逐项核对效果。
用法::
uv run python examples/send_all_types.py
可选参数:
--skip active critical 跳过部分级别
--device-key <key> 指定设备密钥
--base-url <url> 指定服务器地址
每发一条会在终端打印进度,手机端请对照标题核对。
"""
from __future__ import annotations
import argparse
import time
from typing import List, Optional
from bark_notify import BarkClient, Level, Notification
def main(argv: Optional[List[str]] = None) -> int:
parser = argparse.ArgumentParser(description="发送全部类型的 Bark 通知")
parser.add_argument(
"--skip",
nargs="*",
choices=[level.value for level in Level],
default=[],
help="要跳过的级别(可多个)",
)
parser.add_argument("--device-key", help="Bark 设备密钥")
parser.add_argument("--base-url", help="Bark 服务器地址")
args = parser.parse_args(argv)
client = BarkClient(base_url=args.base_url, device_key=args.device_key)
# 第一波:五种级别,逐项核对打扰程度差异
cases = [
("基础通知(default", Level.DEFAULT, {}),
("活跃通知(active", Level.ACTIVE, {}),
("时效性通知(timeSensitive", Level.TIME_SENSITIVE, {}),
("紧急通知(critical", Level.CRITICAL, {"sound": "alarm.caf", "volume": 10}),
("静默通知(passive", Level.PASSIVE, {}),
]
for i, (title, level, extra) in enumerate(cases, start=1):
if level.value in args.skip:
print(f"[{i}/{len(cases)}] 跳过 {level.value}")
continue
notification = Notification(
title=f"[{i}] {title}",
body=f"级别: {level.value}\n由 examples/send_all_types.py 发送",
level=level,
**extra,
)
client.push(notification)
print(f"[{i}/{len(cases)}] 已发送 {level.value}")
time.sleep(1)
# 第二波:特殊功能
features = [
("[6] Markdown 富文本", "### 任务清单\n- [x] 发基础通知\n- [x] 发特殊通知\n- [ ] 核对效果\n\n**加粗** 与 *斜体* 测试 ✅", {}),
("[7] 自定义铃声", "使用 bells 铃声,不同于默认铃声。", {"sound": "bell.caf"}),
("[8] 分组折叠", "属于「演示分组」组,下一条同组。", {"group": "演示分组"}),
("[9] 分组折叠", "属于「演示分组」组,会与上一条折叠。", {"group": "演示分组"}),
("[10] 跳转链接", "点击这条会打开百度。", {"url": "https://www.baidu.com"}),
("[11] 复制文本", "长按这条可复制「OPC 云超服」。", {"copy": "OPC 云超服"}),
("[12] 带图片", "附带一张示例图片,需设备可加载外网图。", {"image": "https://picsum.photos/seed/bark/400/300"}),
]
for i, (title, body, extra) in enumerate(features, start=6):
notification = Notification(title=title, body=body, **extra)
client.push(notification)
print(f"[{i}] 已发送 {title}")
time.sleep(1)
print("全部发送完成,请到手机端核对。")
return 0
if __name__ == "__main__":
raise SystemExit(main())