Skip to content

Instantly share code, notes, and snippets.

@techeverri
Last active July 16, 2021 14:29
Show Gist options
  • Save techeverri/e4c43dcf560466bb5019c8ef9cc3d6fd to your computer and use it in GitHub Desktop.
Save techeverri/e4c43dcf560466bb5019c8ef9cc3d6fd to your computer and use it in GitHub Desktop.
Export all pushes from Pushbullet to a JSON
(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();
}
})();
@RayBB
Copy link

RayBB commented Aug 12, 2016

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

@techeverri
Copy link
Author

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>

@callaginn
Copy link

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