Skip to content

Instantly share code, notes, and snippets.

@rvvvt
Last active June 11, 2020 23:51
Show Gist options
  • Save rvvvt/8fba8adc8d230ea01d728cd809d86952 to your computer and use it in GitHub Desktop.
Save rvvvt/8fba8adc8d230ea01d728cd809d86952 to your computer and use it in GitHub Desktop.
var input = `
Paste list of First and last names here
`;
var names = input.trim().split('\n');
var people = [];
var i = 0;
function loop() {
setTimeout( function() {
console.log( 'run number ' + i );
if (i > 0) {
var j = i - 1;
people[j] = {};
var firstEntry = jQuery('li.search-result').first();
if( firstEntry.length > 0 )
{
people[j].name = firstEntry.find('span.actor-name').text().trim();
people[j].link = firstEntry.find('a').prop('href').trim();
people[j].des = firstEntry.find('p.subline-level-1').text().replace(/[\n\r]+/g, '').trim();
people[j].loc = firstEntry.find('p.subline-level-2').text().replace(/[\n\r]+/g, '').trim();
people[j].pos = firstEntry.find('p.mt2').text().replace(/[\n\r]+/g, '').trim();
console.log( 'stored ' + people[j].name );
}else{
people[j].name = names[j];
people[j].link = 'not found';
people[j].des = 'not found';
people[j].loc = 'not found';
people[j].pos = 'not found';
}
}
if( i < names.length ) {
$('.search-typeahead-v2 artdeco-typeahead-deprecated-input')[0].dispatchEvent(new Event('focus'));
$('.search-typeahead-v2 artdeco-typeahead-deprecated-input input')[0].value = names[i];
$('.search-typeahead-v2 artdeco-typeahead-deprecated-input input')[0].dispatchEvent(new Event('input'));
Ember.run(() => {
var blerg = $.Event('keydown');
blerg.which = 13;
blerg.keyCode = 13;
this.$('form#extended-nav-search input').focus();
this.$('form#extended-nav-search input').trigger(blerg);
});
i++;
loop();
}
else wrapup(people);
}, 3000);
}
function wrapup(people)
{
console.log(people);
var tsv = tabValues(people);
var hiddenElement = document.createElement('a');
hiddenElement.href = 'data:text/csv;charset=utf-8,' + encodeURI(tsv);
hiddenElement.target = '_blank';
hiddenElement.download = 'people.csv';
hiddenElement.click();
}
function tabValues(array) {
var keys = Object.keys(array[0]);
var result = keys.join("\t") + "\n";
array.forEach(function(obj){
keys.forEach(function(k, ix){
if (ix) result += "\t";
result += obj[k];
});
result += "\n";
});
return result;
}
loop();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment