Skip to content

Instantly share code, notes, and snippets.

@AdamBrouwersHarries
Created February 1, 2016 16:50
Show Gist options
  • Save AdamBrouwersHarries/507584f697a41446888c to your computer and use it in GitHub Desktop.
Save AdamBrouwersHarries/507584f697a41446888c to your computer and use it in GitHub Desktop.
A small python script for pushbullet interaction from the command line. Very much based on the weebullet source, with some modifications.
#!/bin/python2
import sys
import json
import requests
apikey = "REDACTED"
def send_push(title, body):
print "Sending push. Title: [%s], body: [%s]\n" % (title, body)
apiurl = "https://api.pushbullet.com/v2/pushes"
timeout = 20000 # arbitary value
if len(title) is not 0 or len(body) is not 0:
payload = json.dumps({'type':'note', 'title':title, 'body':body.encode('utf-8')})
headers = {'Access-Token': apikey, 'Content-Type': 'application/json'}
try:
r = requests.post(apiurl, data=payload, headers=headers, timeout=timeout)
if r.status_code is 401 or r.status_code is 403:
print "Invalid API token: %s\n" % apikey
if r.status_code is not 200:
print "Error sending to pushbullet: %s - %s - %s\n" % (apiurl, r.status_code, body)
except Exception, e:
raise e
def main(pushval):
send_push("Push from the command line!", pushval)
if __name__ == '__main__':
try:
main(sys.argv[1])
except IndexError, e:
print "Failed to push: no text given"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment