Skip to content

Instantly share code, notes, and snippets.

@xaman
Created December 19, 2017 10:00
Show Gist options
  • Save xaman/a2489b8b1cf557995c5803b15b98d1d9 to your computer and use it in GitHub Desktop.
Save xaman/a2489b8b1cf557995c5803b15b98d1d9 to your computer and use it in GitHub Desktop.
Send file to Pushbullet
#
# https://dade.co.za/2016/06/17/simple-python-script-to-send-a-pushbullet-image/
#
import json
import requests
import sys
import os
# This is not a valid token, get your access token from https://www.pushbullet.com/#settings
token = "<TOKEN>"
recipient = "<EMAIL>"
if (len(sys.argv) < 2):
print "USAGE: %s <filename>" % (sys.argv[0])
sys.exit()
a = sys.argv
a.pop(0)
apk_file = " ".join(a)
if not os.path.isfile(apk_file):
print "file does not exist"
sys.exit()
file_name = os.path.basename(apk_file)
res = requests.post("https://api.pushbullet.com/v2/upload-request",
headers={
"Access-Token": token,
"Content-Type": "application/json"
},
data=json.dumps({"file_name": file_name, "file_type": "image/jpeg"}))
js = json.loads(res.content)
files = {'file': open(apk_file, 'rb')}
requests.post(js['upload_url'], files=files)
fileurl = js['file_url']
res = requests.post("https://api.pushbullet.com/v2/pushes",
headers={
"Access-Token": token,
"Content-Type": "application/json"},
data=json.dumps({
"email": recipient,
"type": "file",
"file_name": file_name,
"file_type": "application/vnd.android.package-archive",
"file_url": fileurl}))
@vicenterocha
Copy link

Thanks for sharing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment