推送通知

pushno的Python项目详细描述


pushno是一个python包,用于向mobile发送推送通知 设备。它提供了一个简单、通用的接口来发送推送通知 通过两个服务PushOverProwl

pushno主要关注python 3.x,因此python 2.x将没有遗留的支持。 添加。

模块安装

安装最新版本^{tt1}的最简单方法$ 模块通过pip

pip install -U pushno

或者克隆/下载此存储库并安装:

python setup.py install

基本设置

在第一步中,您需要在 PushOverProwl 并创建一个要使用的对应api密钥。

示例

使用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)

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Drools:不触发规则2,而在内部触发规则1(进入循环)   java有一个易于破解的开源Tivo媒体服务器吗?   Elasticsearch中termFilter与mustFilter in、shouldFilter和orFilter之间的java差异   java在两台计算机之间传输文件   Java主版本不匹配   hibernate Java Netbeans BeanCreationException   java如何在JFreeChart linechart中显示数据库值   java多个持久性错误IntelliJ   java在Python 3.6中调用sklearn2pmml()函数会引发RuntimeError   java正在执行包含在带有空格的文件夹中的cmd文件   java Spring Boot无法访问REST控制器   Java Spring启动外部日志文件jar   java为什么Clojure用未检查的异常包装检查的异常?   java使用ANTLR4获取方法的注释   Java:通用静态多维数组   java JavaFX了解场景状态(打开或关闭)