Last active
August 29, 2015 14:15
-
-
Save bjarneo/66337d2a2643a3f1637c to your computer and use it in GitHub Desktop.
Pushbullet - send basic note
This file contains hidden or 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 python | |
import urllib | |
import urllib2 | |
import base64 | |
import json | |
config = { | |
'api': 'https://api.pushbullet.com/v2/pushes', | |
'token': 'your_token' | |
} | |
def sendMessage(title='', msg=''): | |
data = urllib.urlencode({ | |
'type': 'note', | |
'title': title, | |
'body': msg | |
}) | |
auth = base64.encodestring('%s:' % config['token']).replace('\n', '') | |
try: | |
req = urllib2.Request(config['api'], data) | |
req.add_header('Authorization', 'Basic %s' % auth) | |
response = urllib2.urlopen(req) | |
except urllib2.HTTPError: | |
print 'Failed much' | |
return False | |
res = json.load(response) | |
if res['sender_name']: | |
print 'Pushbullet Success' | |
else: | |
print 'Pushbullet Fail' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment