Skip to content

Instantly share code, notes, and snippets.

@bjarneo
Last active August 29, 2015 14:15
Show Gist options
  • Save bjarneo/66337d2a2643a3f1637c to your computer and use it in GitHub Desktop.
Save bjarneo/66337d2a2643a3f1637c to your computer and use it in GitHub Desktop.
Pushbullet - send basic note
#!/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