【问题标题】:Sending Notifications to Android via PushBullet with Python使用 Python 通过 PushBullet 向 Android 发送通知
【发布时间】:2019-05-17 05:51:25
【问题描述】:

特种部队,

我在 reddit 上看到一个关于将 Python 与 Pushbullet 结合使用的帖子,并认为它会很方便,所以我尝试使用 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

运行以下代码:

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)

返回:

[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 示例中存在语法错误,在结束括号之前不应有句号/句点。

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

【问题讨论】:

    标签: python python-2.7


    【解决方案1】:

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

    只需使用 Azelphur 的这个库:

    https://github.com/Azelphur/pyPushBullet

    像魅力一样工作。

    修改导入为

    “从 pushbullet2 导入 PushBullet”

    将库文件名保存为“pushbullet2.py”以避免与“pushbullet.py”冲突(也将新库保存在同一文件夹中)。确保下载自述文件中列出的依赖项,所有这些都可以通过 pip 获得。

    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")
    

    【讨论】:

      【解决方案2】:

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

      您可以在这里找到源代码和文档:
      https://github.com/ltpitt/python-simple-notifications

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

      简单通知

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

      要求

      • Python:如果你有 Linux 或 Mac,你应该很高兴,你应该跳到下一步,如果你在 Windows 上并且你喜欢 lazy'n'great,你可以点击几下安装 Python: http://ninite.com
      • Python Pip:这里是installation instructions

      如何安装

      一旦安装了 Python 和 Python Pip:

      $ git clone https://github.com/ltpitt/python-simple-notifications.git
      $ cd python-simple-notifications
      $ pip install .
      

      然后使用所需的 Email / Pushbullet / Pushover 配置数据自定义 simple_notifications_config.py。如果您阅读 simple_notifications_config.py 中的 cmets,很容易理解。

      使用 Python 2.7 安装 Windows 10 的 simple_notification_config.py 路径示例:
      C:\Python27\Lib\site-packages\simple_notifications\simple_notifications_config.py

      使用 Python 3.7 安装 Windows 10 的 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 上:

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

      用法

      显示帮助的方法如下:

      $ simple-notifications --help
      

      输出:

      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
      
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-06-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-09-04
        • 1970-01-01
        相关资源
        最近更新 更多