使用 Python 通过 PushBullet 向 Android 发送通知 [英] Sending Notifications to Android via PushBullet with Python

查看:30
本文介绍了使用 Python 通过 PushBullet 向 Android 发送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

特种部队,

我在 reddit 上看到一个关于将 Python 与 Pushbullet 结合使用的线程,并认为它会很方便,所以我尝试使用 Python 通过 PushBullet 发送通知,但是我遇到了几个问题

I saw a thread on reddit about using Python with Pushbullet and thought it would be handy so I'm trying to use Python to send Notifications via PushBullet however I'm running into several problems

1) 我无法找出每个 ID 与哪个设备相关...

1) I'm unable to find out what device each ID is related to...

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

PushBullet.py = https://pypi.python.org/pypi/pushbullet.py/0.4.1
Project 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)

返回:

<代码> [设备( 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890',1234567890),设备( 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890',0000000000),设备( 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890',1111111111),设备( 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890',2222222222)]没有任何回溯(最近一次调用最后一次):文件C:\Users\Admin\Desktop\PushBullet_Test.py",第 9 行,在 <module> 中push = phone.push_note("这是标题", "这是正文")AttributeError: 'NoneType' 对象没有属性 'push_note'

请注意,他们的文档在 push_note 示例中存在语法错误,在结束括号之前不应有句号/句点.

Please note that their documentation has a syntax error in the push_note example, it shouldn't have a full stop / period before the end bracket.

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

I can't find any fix anywhere for this problem and can't even find anyone with the problem :(

推荐答案

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

I've built (yet) another CLI Tool in Python that allows you to very quickly and easily use Email / Pushover / Pushbullet notifications.

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

Here you can find source code and documentation:
https://github.com/ltpitt/python-simple-notifications

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

I will also put here the relevant information for simplicity:

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

Simple Notifications is a cross-platform command line tool that allows to easily send out Email (also with attachment) and push notifications (using Pushover or Pushbullet)

要求

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

    Once Python and Python Pip are installed:

    $ 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 中的注释,很容易理解如何.

    Then customize simple_notifications_config.py with the required Email / Pushbullet / Pushover configuration data. It is easy to understand how if you read the comments in simple_notifications_config.py.

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

    Example simple_notification_config.py path for a Windows 10 installation using Python 2.7:
    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

    Example simple_notification_config.py path for a Windows 10 installation using Python 3.7:
    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

    Example simple_notification_config.py path for a Linux installation:
    /usr/local/lib/python2.7/dist-packages/simple_notifications/simple_notifications_config.py

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

    As last step remember to make the simple_notification_config.py file readable only for the user that will run the script.

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

    On Windows right click on the file, properties and then customize the permissions tab using this explanation:

    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  
    

    用法

    以下是显示帮助的方法:

    Usage

    Here's how to display help:

    $ 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
    
    

    这篇关于使用 Python 通过 PushBullet 向 Android 发送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆