Last active
September 9, 2023 17:09
-
-
Save Timopheym/cc86243ece48e512b4c6 to your computer and use it in GitHub Desktop.
Small script to download your pinterest boards to your machine. Limit 50 pins per board... but you can download all pins from board using instruction inside ;)
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
var request = require("request"); | |
var fs = require("fs"); | |
var api_root = 'http://widgets.pinterest.com/v3/pidgets/boards/'; | |
var sync_dir = './images', image_url, image_path, current_user_boards, current_user_name, board_dir; | |
var users = { | |
timopheym : [ | |
'skatches', | |
'home', | |
'lamp', | |
'shelf', | |
'everyday-paint-inspiration' | |
], | |
maher97103 : [ | |
'andrea-joseph', | |
'leonardo-da-vinci' | |
] | |
}; | |
// How to get pins list of the board | |
// Open board in browser | |
// Load ALL pins | |
// Open console and make a breakpoint in the script something like _requestMoreItemsIfNeeded method | |
// Scroll a bit | |
// When breakpoint relesed | |
// execute | |
// JSON.stringify(this.children.map(function (p) { return p.data.id; })); | |
// And You'll get list of pins =) | |
// sync_pins('maher97103', 'leonardo-da-vinci', ["418412621608770303","418412621608770241","418412621608437553","418412621607942285","418412621607631847","418412621607426847","418412621607426844","418412621607426840","418412621607426836","418412621607426835","418412621607426832","418412621607426830","418412621607426823","418412621607426818","418412621607426815","418412621607377065","418412621607134667","418412621607134665","418412621607134658","418412621607108839","418412621607108836","418412621606947718","418412621606824228","418412621606733571","418412621606733567","418412621606733565","418412621606733562","418412621606668600","418412621606581540","418412621606415445","418412621606415427","418412621606415425","418412621606401348","418412621606260283","418412621606184571","418412621605866997","418412621605662597","418412621605475179","418412621605465295","418412621605465293","418412621605141624","418412621605141620","418412621605011334","418412621604877609","418412621604872082","418412621604854124","418412621604854117","418412621604854116","418412621604854114","418412621604854112","418412621604854110","418412621604854106","418412621604854100","418412621604854097","418412621604854091","418412621604854088","418412621604854081","418412621604854077","418412621604854070","418412621604854069","418412621604854066","418412621604783114","418412621604771154","418412621604723588","418412621604723584","418412621604611603","418412621604592937","418412621604575819","418412621604575818","418412621604575817","418412621604575814","418412621604575813","418412621604575812","418412621604575810","418412621604575808","418412621604575807","418412621604575806","418412621604548118","418412621604473931","418412621604455055","418412621604455053","418412621604455051","418412621604455047","418412621604455039","418412621604455038","418412621604455036","418412621604455034","418412621604455031","418412621604455030","418412621604455028","418412621604455026","418412621604455023","418412621604455021","418412621604433574","418412621604404197","418412621604397186","418412621604361265","418412621604361263","418412621604361260","418412621604361258","418412621604361252","418412621604361250","418412621604361249","418412621604361245","418412621604361240","418412621604357878","418412621604357873","418412621604357866","418412621604357864","418412621604249047","418412621604129816","418412621604052079","418412621604052073","418412621604052068","418412621604052060","418412621604052049","418412621604051888","418412621604042305","418412621603992527","418412621603992525","418412621603936311","418412621603936308","418412621603936306","418412621603920044","418412621603920041","418412621603920034","418412621603889201","418412621603889198","418412621603889195","418412621603818099","418412621603818093","418412621603817964","418412621603817963","418412621603677083","418412621603487856","418412621603269741","418412621603221493","418412621603162293","418412621603162283","418412621603162257","418412621603160138","418412621603144270","418412621603054299","418412621603054290","418412621602914603","418412621602872747","418412621602773841","418412621602705847","418412621602705843","418412621602705841","418412621602705839","418412621602705838","418412621602705836","418412621602705831","418412621602705827","418412621602705824","418412621602705822","418412621602641309","418412621602641308","418412621602626750","418412621602599168","418412621602546928","418412621602546925","418412621602546924","418412621602546921","418412621602546918","418412621602546917","418412621602546915","418412621602546914","418412621602546912","418412621602539677","418412621602469742","418412621602469739","418412621602469738","418412621602469733","418412621602469731","418412621602469729","418412621602469725","418412621602469723","418412621602469721","418412621602469719","418412621602469716","418412621602469713","418412621602469711","418412621602469710","418412621602469708","418412621602469704","418412621602469701","418412621602469696","418412621602469692","418412621602469429"]); | |
// After that you can call sync_pins('user_name', 'board_name', [list_of_pins]); //Folder have to be exist | |
sync_user('timopheym'); | |
setTimeout(function(){ | |
sync_user('maher97103'); | |
}, 10000) | |
setTimeout(function(){ | |
sync_pins('maher97103', 'leonardo-da-vinci', ["418412621608770303","418412621608770241","418412621608437553","418412621607942285","418412621607631847","418412621607426847","418412621607426844","418412621607426840","418412621607426836","418412621607426835","418412621607426832","418412621607426830","418412621607426823","418412621607426818","418412621607426815","418412621607377065","418412621607134667","418412621607134665","418412621607134658","418412621607108839","418412621607108836","418412621606947718","418412621606824228","418412621606733571","418412621606733567","418412621606733565","418412621606733562","418412621606668600","418412621606581540","418412621606415445","418412621606415427","418412621606415425","418412621606401348","418412621606260283","418412621606184571","418412621605866997","418412621605662597","418412621605475179","418412621605465295","418412621605465293","418412621605141624","418412621605141620","418412621605011334","418412621604877609","418412621604872082","418412621604854124","418412621604854117","418412621604854116","418412621604854114","418412621604854112","418412621604854110","418412621604854106","418412621604854100","418412621604854097","418412621604854091","418412621604854088","418412621604854081","418412621604854077","418412621604854070","418412621604854069","418412621604854066","418412621604783114","418412621604771154","418412621604723588","418412621604723584","418412621604611603","418412621604592937","418412621604575819","418412621604575818","418412621604575817","418412621604575814","418412621604575813","418412621604575812","418412621604575810","418412621604575808","418412621604575807","418412621604575806","418412621604548118","418412621604473931","418412621604455055","418412621604455053","418412621604455051","418412621604455047","418412621604455039","418412621604455038","418412621604455036","418412621604455034","418412621604455031","418412621604455030","418412621604455028","418412621604455026","418412621604455023","418412621604455021","418412621604433574","418412621604404197","418412621604397186","418412621604361265","418412621604361263","418412621604361260","418412621604361258","418412621604361252","418412621604361250","418412621604361249","418412621604361245","418412621604361240","418412621604357878","418412621604357873","418412621604357866","418412621604357864","418412621604249047","418412621604129816","418412621604052079","418412621604052073","418412621604052068","418412621604052060","418412621604052049","418412621604051888","418412621604042305","418412621603992527","418412621603992525","418412621603936311","418412621603936308","418412621603936306","418412621603920044","418412621603920041","418412621603920034","418412621603889201","418412621603889198","418412621603889195","418412621603818099","418412621603818093","418412621603817964","418412621603817963","418412621603677083","418412621603487856","418412621603269741","418412621603221493","418412621603162293","418412621603162283","418412621603162257","418412621603160138","418412621603144270","418412621603054299","418412621603054290","418412621602914603","418412621602872747","418412621602773841","418412621602705847","418412621602705843","418412621602705841","418412621602705839","418412621602705838","418412621602705836","418412621602705831","418412621602705827","418412621602705824","418412621602705822","418412621602641309","418412621602641308","418412621602626750","418412621602599168","418412621602546928","418412621602546925","418412621602546924","418412621602546921","418412621602546918","418412621602546917","418412621602546915","418412621602546914","418412621602546912","418412621602539677","418412621602469742","418412621602469739","418412621602469738","418412621602469733","418412621602469731","418412621602469729","418412621602469725","418412621602469723","418412621602469721","418412621602469719","418412621602469716","418412621602469713","418412621602469711","418412621602469710","418412621602469708","418412621602469704","418412621602469701","418412621602469696","418412621602469692","418412621602469429"]); | |
}, 20000) | |
function sync_user(user_name) { | |
console.log('Syncing', user_name); | |
current_user_name = user_name; | |
current_user_boards = users[user_name]; | |
createFolderIfNotExist(sync_dir + '/' + user_name); | |
current_user_boards.forEach(sync_board); | |
}; | |
function createFolderIfNotExist(path) { | |
if (!fs.existsSync(path)){ | |
fs.mkdirSync(path); | |
} | |
} | |
var download = function(uri, filename){ | |
request.head(uri, function(err, res, body){ | |
request(uri).pipe(fs.createWriteStream(filename)); | |
}); | |
}; | |
function sync_pins(user, board, pins) { | |
var i = 0, pin_ids = '', inter = setInterval(function(){ | |
if (!isNaN(pins[i])) { | |
pin_ids += pins[i] + ','; | |
} | |
i++; | |
if (i == pins.length) { | |
clearInterval(inter); | |
return; | |
} | |
if (!(i % 20) || i == pins.length) { | |
console.log('http://widgets.pinterest.com/v3/pidgets/pins/info/?pin_ids=' + pin_ids.slice(0,-1)) | |
request({ | |
url: 'http://widgets.pinterest.com/v3/pidgets/pins/info/?pin_ids=' + pin_ids.slice(0,-1), | |
json: true | |
}, function (error, response, body) { | |
body.data.forEach(function(pin) { | |
image_url = pin.images['237x'].url; | |
image_url = image_url.replace('237x', 'originals'); | |
image_path = sync_dir + '/' + user + '/' + board + '/' + pin.id + '.' + image_url.split('.').pop(); | |
if (!fs.existsSync(image_path)) { | |
setTimeout(download(image_url, image_path), 800); | |
console.log('Saving', image_url) | |
} | |
}) | |
}); | |
pin_ids = ''; | |
} | |
}, 300) | |
} | |
function sync_board(board_name) { | |
board_dir = sync_dir + '/' + current_user_name+ '/' + board_name | |
createFolderIfNotExist(sync_dir + '/' + current_user_name + '/' + board_name); | |
request({ | |
url: api_root + current_user_name + '/' + board_name + '/pins', | |
json: true | |
}, function (error, response, body) { | |
if (!error && response.statusCode === 200) { | |
body.data.pins.forEach(function(pin){ | |
image_url = pin.images['237x'].url; | |
image_url = image_url.replace('237x', 'originals'); | |
image_path = sync_dir + '/' + current_user_name + '/' + board_name + '/' + pin.id + '.' + image_url.split('.').pop(); | |
if (!fs.existsSync(image_path)) { | |
setTimeout(download(image_url, image_path), 500); | |
console.log('Saving', image_url) | |
} | |
}) | |
} else { | |
console.log(error, response.statusCode) | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment