Pushing to Pushbullet with Python

I’ve played with Pushbullet as a cheaper way to drive notifications of events from my household zwave system. For instance I’m pushing this service to push notifications of the front door bell to tablets and phones. Here is is some example Python code to get started pushing.

 

import os
import sys
import json
import httplib

kPushbulletUrl = "api.pushbullet.com"
kPushbulletPushUrl = "/v2/pushes"
kPushbulletUploadRequestUrl = "/v2/upload-request"
kPushbulletUploadUrl = "/v2/pushbullet-uploads"

def pushbullet(inTitle, inBody, inFile):
    headers = {"Authorization": "Bearer %s" % kPushbulletToken,
               "Content-Type": "application/json"}    

    #requestDict = {"type": "note", "title": inTitle, "body": inBody}

    strUrl = "http://<url>" % inFile
    requestDict = {"type": "link", "title": inTitle, "body": inBody, "url" : strUrl}

    body = json.dumps(requestDict)
    conn = httplib.HTTPSConnection(kPushbulletUrl)
    conn.request("POST", kPushbulletPushUrl, body, headers)
    response = conn.getresponse()
    if 200 == response.status:
        data = response.read()
        print(data)
    else:
        print("%s%s" % (response.status, response.reason))

    conn.close()