Skip to content

Instantly share code, notes, and snippets.

@grgaortiz
Last active August 25, 2015 20:24
Show Gist options
  • Save grgaortiz/02c79538e151b7b5715d to your computer and use it in GitHub Desktop.
Save grgaortiz/02c79538e151b7b5715d to your computer and use it in GitHub Desktop.
A simple node.js script to pull Utah startups from AngelList into CSV file.
// Load required packages
var fs = require('fs');
var csv = require('csv');
var async = require('async');
var angel = require('angellist');
var json2csv = require('json2csv');
// Set this to your AngelList params for your registered application
var clientID = '';
var clientSecret = '';
// Init the object with your API key
angel.init(clientID, clientSecret);
/*
Retrieve Startups from AnagelList by tag ID
*/
// Create array of functions to run in parallel
var functionsToRunAsync = [];
// CSV field names
var fields = [
'name'
, 'angellist_url'
, 'logo_url'
, 'product_desc'
, 'high_concept'
, 'follower_count'
, 'company_url'
, 'twitter_url'
, 'blog_url'
, 'linkedin_url'
, 'company_size'
, 'location'
];
// Vars to hold data
var data = [];
var pages = [];
// tag ID for Utah on AngelList
var tagID = '1689';
var pageCount = 0;
var startupCount = 0;
// Loop through AngelList paginated results,
// adding a async function for each page to
// parse the results and load into array
for (var page = 1; page <= 21; page++) {
pages.push(page);
functionsToRunAsync.push(function (callback) {
var page = pages[pageCount];
angel.searchByStartupTag(tagID, page, function (error, results) {
if (!error) {
var startups = results.startups;
for (var i = 0; i < startups.length; i++) {
location = '';
if(startups[i].locations) {
location = startups[i].locations[0].display_name;
}
if(startups[i].name) {
var startup = {
'name': startups[i].name
, 'angellist_url': startups[i].angellist_url
, 'logo_url': startups[i].logo_url
, 'product_desc': startups[i].product_desc
, 'high_concept': startups[i].high_concept
, 'follower_count': startups[i].follower_count
, 'company_url': startups[i].company_url
, 'twitter_url': startups[i].twitter_url
, 'blog_url': startups[i].blog_url
, 'linkedin_url': startups[i].linkedin_url
, 'company_size': startups[i].company_size
, 'location': location
};
startupCount++;
data.push(startup);
}
}
callback();
} else {
console.log(error);
callback();
}
});
pageCount++;
});
}
// Let's run the functions and build the CSV
async.parallel(
functionsToRunAsync,
function (err, results) {
json2csv({data: data, fields: fields}, function (err, csv) {
if (err) console.log(err);
fs.writeFile('utahStartups.csv', csv, function (err) {
if (err) throw err;
console.log('File saved. There were ' + startupCount + ' records.');
});
});
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment