Giuseppe Parrello

 

Python - How to send a Pushbullet push


In this page I provide you with Python scripts in order to send a Pushbullet's push. Please take note of the following requirements:

For further details about Pushbullet's API, refer to this page.


Sending a push "Note"

#!/usr/bin/env python

# Remember to install the Pushbullet library using "pip install pushbullet.py".

import logging
from pushbullet import Pushbullet

logging.basicConfig(level=logging.DEBUG)

TOKEN_ID = ''
BODY     = "This is the body"
TITLE    = "This is the title"

def main():
    pb = Pushbullet(TOKEN_ID)

    # Pushing a text note
    push = pb.push_note(BODY, TITLE)

if __name__ == '__main__':
    main()

 

Sending a push "Link"

#!/usr/bin/env python

# Remember to install the Pushbullet library using "pip install pushbullet.py".

import logging
from pushbullet import Pushbullet

logging.basicConfig(level=logging.DEBUG)

TOKEN_ID = ''
BODY     = "This is the body"
TITLE    = "This is the title"
LINK     = "https://www.google.com"

def main():
    pb = Pushbullet(TOKEN_ID)

    # Pushing a link
    push = pb.push_link(TITLE, LINK, BODY)

if __name__ == '__main__':
    main()

 

Sending a push "File"

To send a file, there are two ways. In the first way, we must have a file already available. In the second way, we have to retrieve a file from Internet.
The following script, retrieves a file already in the same folder of the script.

#!/usr/bin/env python

# Remember to install the Pushbullet library using "pip install pushbullet.py".

import logging
from pushbullet import Pushbullet

logging.basicConfig(level=logging.DEBUG)

TOKEN_ID = ''
BODY     = "This is the body"
TITLE    = "This is the title"
FILE     = "picture.jpg"

def main():
    pb = Pushbullet(TOKEN_ID)

    # Pushing a file (file must be uploaded so it must be in the same folder of this script)
    with open(FILE, "rb") as pic:
        file_data = pb.upload_file(pic, FILE)
    file_data["body"]  = BODY
    file_data["title"] = TITLE
    push = pb.push_file(**file_data)

if __name__ == '__main__':
    main()

The following script, retrieves a file from Internet.

#!/usr/bin/env python

# Remember to install the Pushbullet library using "pip install pushbullet.py".

import logging
from pushbullet import Pushbullet

logging.basicConfig(level=logging.DEBUG)

TOKEN_ID = ''
BODY     = "This is the body"
TITLE    = "This is the title"
FILENAME = "pexels.jpg"
FILETYPE = "image/jpeg"
FILEURL  = "https://images.pexels.com/photos/1681148/pexels-photo-1681148.jpeg"

def main():
    pb = Pushbullet(TOKEN_ID)

    # Pushing a file (image is on Internet)
    push = pb.push_file(file_url=FILEURL, file_name=FILENAME, file_type=FILETYPE, body=BODY, title=TITLE)
    
if __name__ == '__main__':
    main()