ntfy ntfy向您的外壳带来通知。长期运行命令完成时,它可以自动提供桌面通知,也可以在特定命令完成时向手机发送推送通知。使困惑?该视频演示了其中一些功能:
$ sudo pip install ntfy
$ ntfy send test
# send a notification when the command `sleep 10` finishes
# this sends the message '"sleep 10" succeeded in 0:10 minutes'
$ ntfy done sleep 10
$ ntfy -b pushover -o user_key t0k3n send ' Pushover test! '
$ ntfy -t ' ntfy ' send " Here's a custom notification title! "
$ echo -e ' backends: ["pushover"]npushover: {"user_key": "t0k3n"} ' > ~ /.ntfy.yml
$ ntfy send " Pushover via config file! "
$ ntfy done --pid 6379 # pid extra
$ ntfy send " :tada: ntfy supports emoji! :100: " # emoji extra
# Enable shell integration
$ echo ' eval "$(ntfy shell-integration)" ' >> ~ /.bashrc快速启动中的安装技术是建议的安装方法。它可以安装在Virtualenv中,但是有了一些警告:Linux通知需要 - 虚拟的--system-site-packages和OS X通知根本不起作用。
?注意: Linux桌面通知需要Python DBU绑定。请参阅此处以获取更多信息。
ntfy支持在Bash和ZSH中长期运行命令完成时自动发送通知。在Bash中,它使用RCALORAS/BASH-PREEXEC模拟ZSH的preexec和PRECMD功能。为了使其添加以下内容到您的.bashrc或.zshrc :
eval " $( ntfy shell-integration ) "默认情况下,它将仅发送持续时间超过10秒的命令的通知,以及终端是否集中。终端焦点在X11(Linux)和MacOS上的terminal.App和iterm2上工作。这两个选项都可以通过--longer-than和--foreground-too选项进行配置。
为了避免运行交互式程序时不必要的通知,在AUTO_NTFY_DONE_IGNORE中列出的程序不会生成通知。例如:
export AUTO_NTFY_DONE_IGNORE= " vim screen meld "ntfy具有一些需要额外依赖性的功能。ntfy done -p $PID需要安装为pip install ntfy[pid]pip install ntfy[emoji]pip install ntfy[xmpp]pip install ntfy[telegram]pip install ntfy[instapush]pip install ntfy[slack]pip install ntfy[rocketchat]要安装多个额外功能,请与逗号分开:例如, pip install ntfy[pid,emoji] 。
ntfy ntfy配置了存储在~/.ntfy.yml或在标准平台特定位置的YAML文件:
~/.config/ntfy/ntfy.yml~/Library/Application Support/ntfy/ntfy.ymlC:Users<User>AppDataLocaldschepntfy.yml后端密钥指定默认情况下要使用的后端。每个后端都有自己的配置,以其自己的名称的键存储。例如:
---
backends :
- pushover
pushover :
user_key : hunter2
pushbullet :
access_token : hunter2
simplepush :
key : hunter2
slack :
token : slacktoken
recipient : " #slackchannel "
xmpp :
jid : " [email protected] "
password : " xxxx "
mtype : " chat "
recipient : " [email protected] "如果您想要同一后端类型的Mulitple配置,则可以指定任何名称,然后使用后端键指定后端。例如:
---
pushover :
user_key : hunter2
cellphone :
backend : pushover
user_key : hunter2有关可用的后端和选项,请参见下面的后端。截至v2.6.0, ntfy还支持第三方后端
pushoveruser_keysoundpriorityexpireretrycallbackapi_token使用您自己的应用程序令牌device - 针对设备(如果省略),将通知发送到所有设备urlurl_titlehtmlpushbulletaccess_token您的PushBullet访问令牌,在https://www.pushbullet.com/#settings/account上创建device_iden设备标识符(如果省略),将通知发送到所有设备email - 通过指定的电子邮件将通知发送给PushBullet用户,或者如果不是Pushullet用户,请发送电子邮件simplepushkey - 通过在https://simplepush.io上安装Android应用程序(无需注册)创建的SimplePush键event - 设置铃声和传入通知的振动模式(可以在SimplePush应用中定义)xmppjidpasswordrecipienthostname (如果不是来自JID)portpath_to_certsmtype需要额外的安装,这样: pip install ntfy[xmpp] 。
验证服务器提供的SSL证书:path_to_certs =“ path/to/ca/cert”
如果没有安装DNSpython库,则需要指定服务器主机名,如果它与JID不匹配。
指定端口,如果其他5222。注意:没有指定的主机名忽略
注意:Google Hangouts自2017年以来不支持XMPP
telegram需要额外的安装: pip install ntfy[telegram] 。
要求将ntfy安装为ntfy[telegram] 。首次尝试使用它时,对此后端进行了配置: ntfy -b telegram send "Telegram configured for ntfy" 。
pushjetsecret - 用http://docs.pushjet.io/docs/creating-a-a-new-service创建的Pushjet服务秘密令牌endpoint - 自定义的推杆API端点level - 重要性水平从1(低)到5(高)linknotificowebhook -Webhook链接,在https://n.tkte.ch/上创建Plain Text服务)slack需要额外的安装: pip install ntfy[slack] 。
token - The Slack service secret token, either a legacy user token created at https://api.slack.com/custom-integrations/legacy-tokens or a token obtained by creating an app at https://api.slack.com/apps?new_app=1 with chat:write:bot scope and linking it to a workspace.recipient - 将通知发送通知的Slack频道或用户。如果使用#符号,则将消息发送到Slack频道,如果使用@符号,则消息将发送给Slack用户。slack_webhookurl传入Webhook的URLuser - 将通知发送到的Slack Channel或用户insta需要附加功能,像此pip install ntfy[instapush]一样安装。
Instapush不支持通知标题。它发送模板驱动的通知,因此您必须先在仪表板上设置事件。由于具有Instapush Python包装器的同义词,后端称为Insta
appid应用程序IDsecret - 申请秘密event_name要使用的Instapush事件trackers - 驱动器阵列要使用跟踪器上的注意:跟踪器是事件的占位符(一种通知模板)。如果您在活动中定义了多个跟踪器,则必须提供更多消息。目前,这样做的唯一方法是用结肠(:)角色将每个消息分开。您还可以逃脱分离器角色:示例:
ntfy -b insta send " message1:message2 "
ntfy -b insta send " message1:message2:with:colons "prowlapi_keyprovider_keypriorityurllinux通过DBUS工作,与Gnome,KDE,XFCE以及Libnotify一样。
应安装以下依赖项。
$ sudo apt install python-dbus # on ubuntu/debian您将需要安装一些支持表情符号的字体(在Debian Fonts-Symbola或Gentoo Media-Fonts/Symerna中)。
icon - 指定通知图标的路径,无图标的空字符串。urgency - 指定紧迫水平(低,正常,关键)。transient - 跳过历史记录(EXP:GNOME消息托盘)(true,false)。soundfile - 指定通知声音文件(例如/usr/share/sounds/notif.wav)。timeout - 指定通知到期时间级(-1-系统默认,0-永不过期)。win32使用pywin32 。
darwin需要在全球安装ntfy (不在Virtualenv中)。
systemlog使用syslog Core Python模块,该模块在Windows平台上不可用。
prio -Syslog优先级。默认值ALERT 。可能的值是:
facility -Syslog设施。默认值为LOCAL5 。可能的值是:
fmt将发送到系统记录器的消息格式。使用以下占位符指定标题和消息:
{title}{message}默认值为[{title}] {message} 。
termux需要在Play商店安装该应用程序,并使用apt install termux-api安装CLI实用程序。
pushalotauth_token您的私人Pusealot auth Token,此处找到https://pushalot.com/manager/authorizationssource - 通知的来源ttl消息在几分钟内到期时间(生存时间)url在通知中包含的URLurl_title可见的URL标题(如果未指定URL,则忽略)image - 通知中包含的图像的URLimportant - 标记通知很重要silent - 标记通知为沉默rocketchat需要额外的安装: pip install ntfy[rocketchat] 。
url您的火箭的URL。username - 登录用户名password - 登录密码room - 会在matrix需要附加功能,这样安装: pip install ntfy[matrix] 。
url您的HomeServer实例的URLroomId张贴的空间userId登录用户IDpassword - 登录密码token - 访问令牌您必须指定token或userId和password 。
ntfy_webpush WebPush支持由外部NTFY模块提供,以下安装: pip install ntfy ntfy-webpush 。
subscription_info pushSubscription对象private_key私有密钥文件或其他与Pywebpush一起使用的路径。有关更多信息,请参见ntfy-webpush <https://github.com/dschep/ntfy-webpush>`_ _
要使用或实施自己的后端,请指定模块的完整路径作为后端。该模块需要包含一个具有称为notify的函数的模块,并具有以下签名:
def notify ( title , message , ** kwargs ):
"""
kwargs contains retcode if using ntfy done or ntfy shell-integration
and all options in your backend's section of the config
"""
pass标题可与配置中的标题键配置。例子:
---
title : Customized Titlepython setup.py test