Created
February 1, 2016 16:50
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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