推送通知
pushno的Python项目详细描述
pushno是一个python包,用于向mobile发送推送通知 设备。它提供了一个简单、通用的接口来发送推送通知 通过两个服务PushOver和Prowl。
pushno主要关注python 3.x,因此python 2.x将没有遗留的支持。 添加。
模块安装
安装最新版本^{tt1}的最简单方法$ 模块通过pip:
pip install -U pushno
或者克隆/下载此存储库并安装:
python setup.py install
示例
使用pushno发送推送消息的最简单方法是使用 PushNotification类,它为所有可用的 推送通知服务。
徘徊
对于潜行,请执行以下操作:
pn = PushNotification( "prowl", api_key=PUSHNO_PROWL_API_KEY, application="pushno" ) is_valid, res = pn.validate_user() if is_valid: pn.send(event="How simple is that?", description="Great News") else: print(res)
推覆
对于pushover do:
pn = PushNotification( "pushover", token=PUSHNO_PUSHOVER_API_KEY, user=PUSHNO_PUSHOVER_USER_KEY ) is_valid, res = pn.validate_user() if is_valid: pn.send(title="How simple is that?", message="Great News") else: print(res)
注意,验证部分是可选的,所以如果您确定api密钥 工作正常,可以直接发送推送消息。因此, 您可以用两行代码发送推送消息。
也可以直接使用底层客户机类 但是有点冗长:
徘徊
from pushno.plugins import ProwlClient from pushno.messages import ProwlMessage # prepare the pushover client client = ProwlClient(PUSHNO_PROWL_API_KEY) # validate the user key is_valid, res = client.validate_user() if is_valid is True: # key is still valid => send a notification message res = client.send( ProwlMessage( application="pushno", event="How simple is that?", description="Great News" ) ) print(res) else: print(res)
推覆
from pushno.plugins import PushOverClient from pushno.messages import PushOverMessage # prepare the pushover client client = PushOverClient(PUSHNO_PUSHOVER_API_KEY, PUSHNO_PUSHOVER_USER_KEY) # validate the user key is_valid, res = client.validate_user() if is_valid is True: # key is still valid => send a notification message client.send( PushOverMessage( title="Great News", message="How simple is that?" ) ) else: print(res["errors"])
同样,用户api密钥的验证部分是可选的。
有关完整的示例脚本,请参见https://github.com/keans/pushno/tree/master/examples。
开发
如果你想参与开发,请查看源代码 在https://github.com/keans/pushno.git。
开始开发:
git clone git@github.com:keans/pushno.git cd pushno/ python3 -m venv env source env/bin/activate pip install -r requirements.txt
对于详细调试输出,只需将日志记录级别设置为debug:
import logging logging.basicConfig(level=logging.DEBUG)