Last active
July 16, 2021 14:29
-
-
Save techeverri/e4c43dcf560466bb5019c8ef9cc3d6fd to your computer and use it in GitHub Desktop.
Export all pushes from Pushbullet to a JSON
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
(function () { | |
'use strict'; | |
var fs = require('fs'); | |
var https = require('https'); | |
var cursor = ''; | |
var pushes = []; | |
var headers = { | |
'Access-Token': process.argv[2] | |
}; | |
var query = { | |
active: true, | |
modified_after: 1, | |
limit: 500, | |
}; | |
var options = { | |
host: 'api.pushbullet.com', | |
method: 'GET', | |
headers: headers | |
}; | |
getPushes(); | |
function getPushes() { | |
query.cursor = cursor; | |
options.path = '/v2/pushes?' + getQueryString(query); | |
var req = https.request(options, onSuccess); | |
req.end(); | |
req.on('error', onError); | |
} | |
function getQueryString(query) { | |
var queryString = Object.keys(query) | |
.map(function (key) { | |
return key + '=' + encodeURIComponent(query[key]); | |
}) | |
.join('&'); | |
return queryString; | |
} | |
function onSuccess(response) { | |
var data = ''; | |
response.setEncoding('utf8'); | |
response.on('data', function (chunk) { | |
data += chunk; | |
}); | |
response.on('end', function () { | |
data = JSON.parse(data); | |
if (data.error) { | |
pushes = data.error; | |
} else { | |
cursor = data.cursor; | |
pushes = pushes.concat(data.pushes); | |
} | |
whatsNext(); | |
}); | |
} | |
function onError(e) { | |
console.log('problem with request: ' + e.message); | |
} | |
function whatsNext() { | |
if (cursor) { | |
getPushes(); | |
} else { | |
writePushes(JSON.stringify(pushes, undefined, 4)); | |
} | |
} | |
function writePushes(pushesAsString) { | |
var file = fs.createWriteStream('pushes.json'); | |
file.on('error', function (err) { | |
if (err) throw err; | |
}); | |
file.write(pushesAsString); | |
file.end(); | |
} | |
})(); |
This is a Node.js script (without dependencies) using the API to export all pushes to a JSON file
Usage:
node pushbullet-export-pushes.js <your-access-token>
Is there a way to pull Pushbullet SMS texts? All this script seems to pull for me are texts pushed directly from the mobile app? I was mainly using the app just to sync my text messages between my computer to my phone and used Textra as the client.
I can click on the SMS tab of the Pushbullet Chrome extension and see all these messages btw. Just can't figure out a way to put them back on my phone. (Had my Nexus 5x brick on me last week).
Any ideas?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for writing this! I tried it but it was taking a long time so I closed it and started another and that ended immediately. My pushes.json just contained this:
{ "code": "ratelimited", "type": "invalid_request", "message": "You have been ratelimited for performing too many requests/ops in a short period of time, check the X-Ratelimit-* headers included on this response for more information.", "cat": "(=`ω´=)" }
Could add support so it can detect this and let the user know?
Here's the doc on it https://docs.pushbullet.com/#ratelimiting