Created
March 22, 2014 23:33
-
-
Save topnotcher/9716059 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env /usr/local/bin/python2.7 | |
import urllib2 | |
import urllib | |
import base64 | |
import json | |
import argparse | |
parser = argparse.ArgumentParser(description='Push a notification to all of your Pushbullet devices') | |
parser.add_argument('-k', '--key', type=str, required=True, help="The API Key for your pushbullet account") | |
parser.add_argument('-t', '--title', type=str, required=True, help="The title of the notification") | |
parser.add_argument('-b', '--body', type=str, required=True, help="The body of the notification") | |
args = parser.parse_args() | |
auth = base64.encodestring('%s:' % (args.key)).replace('\n','') | |
request = urllib2.Request('https://api.pushbullet.com/api/devices') | |
request.add_header('Authorization', "Basic "+auth) | |
for device in json.load(urllib2.urlopen(request))['devices']: | |
id = device['iden'] | |
data = urllib.urlencode({'type': 'note', 'device_iden': id, 'title': args.title, 'body': args.body}) | |
request = urllib2.Request('https://api.pushbullet.com/api/pushes',data) | |
request.add_header('Authorization', 'Basic '+auth) | |
urllib2.urlopen(request) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment