首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Python通过PushBullet向安卓发送通知

使用Python通过PushBullet向安卓发送通知
EN

Stack Overflow用户
提问于 2014-05-24 22:07:19
回答 2查看 9.7K关注 0票数 1

索夫

我在reddit上看到了一个关于在Pushbullet中使用Python的帖子,我想这会很方便,所以我尝试使用Python通过PushBullet发送通知,但是我遇到了几个问题

1)找不到每个ID对应的设备...

2)由于AttributeError: 'NoneType' object has no attribute 'push_note'错误,我无法向任何设备推送任何内容

PushBullet.py = https://pypi.python.org/pypi/pushbullet.py/0.4.1

Github项目:https://github.com/randomchars/pushbullet.py

运行以下代码:

代码语言:javascript
复制
from pushbullet import PushBullet

pb = PushBullet("ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890")
print pb.devices

phone = pb.get("1234567890")
print phone

push = phone.push_note("This is the title", "This is the body")
print(push.status_code)

返回:

代码语言:javascript
复制
[Device('ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890', 1234567890), Device('ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890', 0000000000), Device('ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890', 1111111111), Device('ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890', 2222222222)]
None

Traceback (most recent call last):
  File "C:\Users\Admin\Desktop\PushBullet_Test.py", line 9, in <module>
    push = phone.push_note("This is the title", "This is the body")
AttributeError: 'NoneType' object has no attribute 'push_note'

请注意,他们的文档在push_note示例中有一个语法错误,它不应该在结束括号之前有一个句号/句号。

我在任何地方都找不到任何解决这个问题的方法,甚至找不到有这个问题的人:

EN

回答 2

Stack Overflow用户

发布于 2014-06-10 06:56:58

今天早些时候也遇到了同样的问题

只需使用Azelphur提供的这个库:

https://github.com/Azelphur/pyPushBullet

就像一种护身符。

将导入修改为

“从pushbullet2导入PushBullet”

将库文件名保存为“also bullet2.py”,以避免与"pushbullet.py“冲突(同时将新库保存在同一文件夹中)。确保下载Read Me中列出的依赖项,所有依赖项都可以通过pip获得。

代码语言:javascript
复制
from pushbullet2 import PushBullet

pb = PushBullet("ABCDEFGHIJKLMOPQRSTUVWXYZ")

devices = pb.getDevices()
phone = devices[0]["iden"] #change number to change device

#print devices
print phone

push = pb.pushNote(phone,"This is title", "This is the body")
票数 1
EN

Stack Overflow用户

发布于 2016-09-21 19:20:50

我已经在Python中构建了另一个CLI工具,它允许您非常快速、轻松地使用电子邮件/ Pushover / Pushbullet通知。

你可以在这里找到源代码和文档:

https://github.com/ltpitt/python-simple-notifications

为了简单起见,我也将相关信息放在这里:

简单的通知

Simple Notifications是一个跨平台的命令行工具,允许轻松发送电子邮件(也包括附件)和推送通知(使用PushoverPushbullet)

要求

如果你有Linux或者Mac,你应该已经准备好了,你应该跳到下一步,如果你在Windows上,并且你喜欢懒惰‘n’,你可以通过点击几下http://ninite.com

如何安装

安装Python和Python Pip后:

代码语言:javascript
复制
$ git clone https://github.com/ltpitt/python-simple-notifications.git
$ cd python-simple-notifications
$ pip install .

然后使用所需的电子邮件/ Pushbullet / Pushover配置数据自定义simple_notifications_config.py。如果你阅读simple_notifications_config.py中的评论,你会很容易理解。

使用Python2.7的Windows10安装的simple_notification_config.py路径示例:

C:\Python27\Lib\site-packages\simple_notifications\simple_notifications_config.py

使用Python3.7的Windows10安装的simple_notification_config.py路径示例:

C:\Users\YOUR_USER\AppData\Local\Programs\Python\Python37\Lib\site-packages\simple_notifications

Linux安装的simple_notification_config.py路径示例:

/usr/local/lib/python2.7/dist-packages/simple_notifications/simple_notifications_config.py

作为最后一步,请记住使simple_notification_config.py文件只对将运行脚本的用户可读。

在Windows上,右键单击文件、属性,然后使用以下说明自定义权限选项卡:

https://msdn.microsoft.com/en-us/library/bb727008.aspx

在Linux上:

代码语言:javascript
复制
$ chmod 400 /usr/local/lib/python2.7/dist-packages/simple_notifications/simple_notifications_config.py  

用法

下面是显示帮助的方法:

代码语言:javascript
复制
$ simple-notifications --help

输出:

代码语言:javascript
复制
Usage: simple-notifications [OPTIONS] COMMAND [ARGS]...

  Simple Notifications sends out email and push notifications from your
  applications (using Pushbullet or Pushover)

Options:
  --help  Show this message and exit.

Commands:
  email       Send a notification using Email
  pushbullet  Send a notification using Pushbullet
  pushover    Send a notification using Pushover
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23845936

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档