Skip to content

Commit 06f351d

Browse files
committed
feat: add bark,chanify,pushdeer support. add docs
1 parent 5e6c631 commit 06f351d

File tree

12 files changed

+358
-26
lines changed

12 files changed

+358
-26
lines changed

README.md

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# ipush
22

3-
APP 推送通知
3+
APP 推送通知。支持往 **钉钉群、飞书群、Lark 群、Bark、Chanify、PushDeer** 推送消息。
44

55
## 使用说明
66

77
1. 安装依赖
88

9+
- https://pypi.org/project/ipush/
10+
911
```shell
1012
pip install -U ipush
1113
```
@@ -14,32 +16,48 @@ pip install -U ipush
1416

1517
```python
1618
from ipush.notify.dingtalk import Dingtalk
17-
from ipush.notify.feishu import Feishu
18-
from ipush.notify.lark import Lark
1919

2020
notify = Dingtalk("token", "secret")
2121
notify.send("ipush test")
22-
23-
notify = Feishu("token", "secret")
24-
notify.send("ipush test")
25-
26-
notify = Lark("token", "secret")
27-
notify.send("ipush test")
2822
```
2923

3024
## 支持平台
3125

32-
| 状态 | **国内**平台 | 官网 | 文档 | 备注 |
33-
| :------- | :---------------- | :-------------------------------------------------------------------------------------------------------- | :--- | :--- |
34-
|**** | **钉钉群机器人** | [https://open.dingtalk.com/](https://open.dingtalk.com/document/robots/customize-robot-security-settings) | - | |
35-
|**** | **飞书群机器人** | [https://open.feishu.cn/](https://open.feishu.cn/document/client-docs/bot-v3/add-custom-bot) | - | |
36-
|**** | **Lark 群机器人** | [https://open.larksuite.com/](https://open.larksuite.com/document/client-docs/bot-v3/add-custom-bot) | - | |
26+
| 状态 | **国内**平台 | 官网 | 文档 | 备注 |
27+
| :------- | :---------------- | :-------------------------------------------------------------------------------------------------------- | :--- | :----------- |
28+
|**** | **钉钉群机器人** | [https://open.dingtalk.com/](https://open.dingtalk.com/document/robots/customize-robot-security-settings) | - | |
29+
|**** | **飞书群机器人** | [https://open.feishu.cn/](https://open.feishu.cn/document/client-docs/bot-v3/add-custom-bot) | - | |
30+
|**** | **Lark 群机器人** | [https://open.larksuite.com/](https://open.larksuite.com/document/client-docs/bot-v3/add-custom-bot) | - | |
31+
|**** | **Bark** | [https://day.app/2021/06/barkfaq/](https://day.app/2021/06/barkfaq/) | - | 仅支持 `iOS` |
32+
|| **Chanify** | [https://www.chanify.net/](https://www.chanify.net/) | - | 仅支持 `iOS` |
33+
|| **PushDeer** | https://www.pushdeer.com/ | - | |
34+
35+
## 开发
3736

38-
## 前置环境
37+
### 前置环境
3938

4039
1. 使用 [**Rye**](https://rye-up.com/) 作为包管理工具
4140

42-
## 单元测试
41+
### 开发
42+
43+
1. 安装依赖包:
44+
45+
```bash
46+
# 同步
47+
rye sync
48+
```
49+
50+
2. 代码检测与格式化:
51+
52+
```bash
53+
# 检测
54+
rye run check
55+
56+
# 格式化
57+
rye run format
58+
```
59+
60+
3. 单元测试:
4361

4462
```bash
4563
# rye test

docs/README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# ipush 使用教程
2+
3+
## 使用
4+
5+
1. **钉钉群**
6+
7+
```python
8+
from ipush.notify.dingtalk import Dingtalk
9+
10+
notify = Dingtalk("token", "secret")
11+
notify.send("ipush test")
12+
```
13+
14+
2. **飞书群**
15+
16+
```python
17+
from ipush.notify.feishu import Feishu
18+
19+
notify = Feishu("token", "secret")
20+
notify.send("ipush test")
21+
```
22+
23+
3. **Lark 群**
24+
25+
```python
26+
from ipush.notify.lark import Lark
27+
28+
notify = Lark("token", "secret")
29+
notify.send("ipush test")
30+
```
31+
32+
4. **Bark**
33+
34+
```python
35+
from ipush.notify.bark import Bark
36+
37+
notify = Bark("token")
38+
notify.send("ipush test")
39+
notify.seturl("https://self-hosted")
40+
notify.send("ipush test custom url")
41+
```
42+
43+
5. **Chanify**
44+
45+
```python
46+
from ipush.notify.chanify import Chanify
47+
48+
notify = Chanify("token")
49+
notify.send("ipush test")
50+
notify.seturl("https://self-hosted")
51+
notify.send("ipush test custom url")
52+
```
53+
54+
6. **PushDeer**
55+
56+
```python
57+
from ipush.notify.pushdeer import PushDeer
58+
59+
notify = PushDeer("token")
60+
notify.send("ipush test")
61+
notify.seturl("https://self-hosted")
62+
notify.send("ipush test custom url")
63+
```

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "ipush"
3-
version = "0.1.1"
3+
version = "0.2.0"
44
description = "Push for python"
55
authors = [
66
{ name = "Jetsung Chan", email = "[email protected]" }

src/ipush/notify/bark.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import json
2+
3+
from ..utils.fetch import Fetch
4+
from .notify import Notify
5+
6+
7+
class Bark(Notify):
8+
"""
9+
Bark通知
10+
"""
11+
12+
def __init__(self, token=''):
13+
self.token = token
14+
self.url = 'https://api.day.app'
15+
16+
def signature(self):
17+
pass
18+
19+
def seturl(self, url):
20+
self.url = url
21+
22+
def requrl(self):
23+
"""
24+
生成请求的 URL
25+
"""
26+
return f'{self.url}/push'
27+
28+
def send(self, message):
29+
"""
30+
发送通知
31+
:param message: 消息内容
32+
"""
33+
req_url = self.requrl()
34+
35+
headers = {
36+
'content-type': 'application/json',
37+
}
38+
req = Fetch()
39+
req.update_headers(headers)
40+
41+
data = {
42+
'body': message,
43+
'device_key': self.token,
44+
}
45+
data = json.dumps(data, indent=4)
46+
req.post(req_url, data=data.encode('utf-8'))
47+
return req.response

src/ipush/notify/chanify.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import json
2+
3+
from ..utils.fetch import Fetch
4+
from .notify import Notify
5+
6+
7+
class Chanify(Notify):
8+
"""
9+
Chanify通知
10+
"""
11+
12+
def __init__(self, token=''):
13+
self.token = token
14+
self.url = 'https://api.chanify.net'
15+
16+
def signature(self):
17+
pass
18+
19+
def seturl(self, url):
20+
self.url = url
21+
22+
def requrl(self):
23+
"""
24+
生成请求的 URL
25+
"""
26+
return f'{self.url}/v1/sender/{self.token}'
27+
28+
def send(self, message):
29+
"""
30+
发送通知
31+
:param message: 消息内容
32+
"""
33+
req_url = self.requrl()
34+
35+
headers = {
36+
'content-type': 'application/json',
37+
}
38+
req = Fetch()
39+
req.update_headers(headers)
40+
41+
data = {
42+
'text': message,
43+
}
44+
data = json.dumps(data, indent=4)
45+
req.post(req_url, data=data.encode('utf-8'))
46+
return req.response

src/ipush/notify/pushdeer.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import json
2+
3+
from ..utils.fetch import Fetch
4+
from .notify import Notify
5+
6+
7+
class PushDeer(Notify):
8+
"""
9+
PushDeer通知
10+
"""
11+
12+
def __init__(self, token=''):
13+
self.token = token
14+
self.url = 'https://api2.pushdeer.com'
15+
16+
def signature(self):
17+
pass
18+
19+
def seturl(self, url):
20+
self.url = url
21+
22+
def requrl(self):
23+
"""
24+
生成请求的 URL
25+
"""
26+
return f'{self.url}/message/push'
27+
28+
def send(self, message):
29+
"""
30+
发送通知
31+
:param message: 消息内容
32+
"""
33+
req_url = self.requrl()
34+
35+
headers = {
36+
'content-type': 'application/json',
37+
}
38+
req = Fetch()
39+
req.update_headers(headers)
40+
41+
data = {
42+
'text': message,
43+
'pushkey': self.token,
44+
}
45+
data = json.dumps(data, indent=4)
46+
req.post(req_url, data=data.encode('utf-8'))
47+
return req.response

tests/test_bark.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import os
2+
3+
import pytest
4+
5+
from ipush.notify.bark import Bark
6+
7+
8+
@pytest.fixture
9+
def access_token():
10+
token = os.environ.get('BarkToken')
11+
custom_url = os.environ.get('BarkCustomURL')
12+
return token, custom_url
13+
14+
15+
@pytest.mark.skipif(not os.environ.get('BarkToken'), reason='Bark Token not provided')
16+
def test_bark(access_token):
17+
token, _ = access_token
18+
notify = Bark(token)
19+
res = notify.send('pypush test')
20+
assert res.status_code == 200
21+
json = res.json()
22+
assert json['code'] == 200
23+
24+
25+
@pytest.mark.skipif(
26+
not os.environ.get('BarkToken') or not os.environ.get('BarkCustomURL'),
27+
reason='Bark Token not provided',
28+
)
29+
def test_bark_custom_url(access_token):
30+
token, custom_url = access_token
31+
notify = Bark(token)
32+
notify.seturl(custom_url)
33+
res = notify.send('pypush test custom url')
34+
assert res.status_code == 200
35+
json = res.json()
36+
assert json['code'] == 200

tests/test_chanify.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import os
2+
3+
import pytest
4+
5+
from ipush.notify.chanify import Chanify
6+
7+
8+
@pytest.fixture
9+
def access_token():
10+
token = os.environ.get('ChanifyToken')
11+
custom_url = os.environ.get('ChanifyCustomURL')
12+
return token, custom_url
13+
14+
15+
@pytest.mark.skipif(
16+
not os.environ.get('ChanifyToken'), reason='Chanify Token not provided'
17+
)
18+
def test_chanify(access_token):
19+
token, _ = access_token
20+
notify = Chanify(token)
21+
res = notify.send('pypush test')
22+
assert res.status_code == 200
23+
24+
25+
@pytest.mark.skipif(
26+
not os.environ.get('ChanifyToken') or not os.environ.get('ChanifyCustomURL'),
27+
reason='Chanify Token not provided',
28+
)
29+
def test_chanify_custom_url(access_token):
30+
token, custom_url = access_token
31+
notify = Chanify(token)
32+
notify.seturl(custom_url)
33+
res = notify.send('pypush test custom url')
34+
assert res.status_code == 200

tests/test_dingtalk.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
@pytest.fixture
9-
def assess_token():
9+
def access_token():
1010
token = os.environ.get('DingtalkToken')
1111
secret = os.environ.get('DingtalkSecret')
1212
return token, secret
@@ -15,9 +15,10 @@ def assess_token():
1515
@pytest.mark.skipif(
1616
not os.environ.get('DingtalkToken'), reason='Dingtalk Token not provided'
1717
)
18-
def test_dintalk(assess_token):
19-
token, secret = assess_token
18+
def test_dintalk(access_token):
19+
token, secret = access_token
2020
notify = Dingtalk(token, secret)
2121
res = notify.send('pypush test')
22+
assert res.status_code == 200
2223
json = res.json()
2324
assert json['errcode'] == 0

0 commit comments

Comments
 (0)