Created
April 18, 2013 15:30
-
-
Save martintajur/5413664 to your computer and use it in GitHub Desktop.
Basic Pipedrive person renamer (splits person's names into 2 and flips the sides, giving the ability to flip first names and last names of persons)
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
/* | |
* Basic Pipedrive person renamer (splits person's names into 2 and flips the sides, giving the ability to flip first names and last names of persons) | |
* | |
* Usage | |
* ===== | |
* First, install pipedrive npm module: | |
* npm install pipedrive | |
* | |
* Then run the script: | |
* node personNamer.js | |
*/ | |
var Pipedrive = require('pipedrive'); | |
var pipedrive = new Pipedrive.Client('YOUR_API_TOKEN_HERE'); | |
function flipNames(start) { | |
var batchSize = 50; | |
pipedrive.Persons.getAll({ start: start, limit: batchSize }, function(err, persons) { | |
var peopleToRename = batchSize; | |
for (var i in persons) { | |
(function(person) { | |
var pieces = person.name.split(' '); | |
var midPoint = Math.round(pieces.length / 2); | |
var newName = pieces.slice(midPoint).join(' ') + ' ' + pieces.slice(0, midPoint).join(' '); | |
person.set('name', newName); | |
setTimeout(function() { | |
person.save(function(err) { | |
console.log(person.name + ' => ' + newName); | |
if (err) console.log(err); | |
peopleToRename--; | |
if (peopleToRename == 0) { | |
setTimeout(function() { | |
flipNames(start + batchSize); | |
}, 5000); | |
} | |
}); | |
}, i * 250); | |
})(persons[i]); | |
} | |
}); | |
}; | |
flipNames(0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment