Skip to content

Instantly share code, notes, and snippets.

@picsoung
Created February 11, 2016 15:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save picsoung/48ba85221015ec367d56 to your computer and use it in GitHub Desktop.
Save picsoung/48ba85221015ec367d56 to your computer and use it in GitHub Desktop.
Script that uses APIstrat API to get all speakers of the conference and run analysis using Namsor API to get gender of speakers
var Q = require("q");
var request = Q.denodeify(require("request"));
var _ = require('underscore')
var SPEAKERS=[];
var RESULTS={}
var r = getAllSpeakers()
.then(function(res){
SPEAKERS = res;
SPEAKERS.forEach(function(s){
addFirstLastName(s);
})
})
.then(function(){
return genderOnArray(SPEAKERS);
})
.then(function(speakers){
speakers.forEach(function(s, index){
countGender(s,index);
})
})
.then(function(speakers){
console.log(RESULTS);
});
function getAllSpeakers(){
var options = {
url: "http://api.apistrat.com/speakers/",
method: "GET",
json: true
}
var response = request(options);
return response.then(function(r){
var body = r[0].body;
return body;
})
}
function addFirstLastName(speakerInfo){
speakerInfo.firstName= speakerInfo.name.split(' ')[0] || ""
speakerInfo.lastName= speakerInfo.name.split(' ')[1] || ""
return speakerInfo;
}
function genderOnArray(arr){
var names =_.map(arr, function(currentObject) {
currentObject.id = currentObject.speaker_id;
return _.pick(currentObject, 'firstName','lastName','id');
});
var options = {
url: "https://api.namsor.com/onomastics/api/json/genderList",
method: "POST",
json: {'names':names},
headers:{
"X-Channel-Secret":"YOUR_NAMSOR_TOKEN",
"X-Channel-User":"YOUR_NAMSOR_USER",
}
}
var response = request(options);
return response.then(function(r){s
var body = r[0].body;
return body.names;
})
}
function countGender(speakerInfo,index){
console.log("count",speakerInfo.gender);
var events = SPEAKERS[index].events.split(', ')
events.forEach(function(e){
if(typeof RESULTS[e] == "undefined"){
RESULTS[e] = {
total:0,
male:0,
female: 0,
unknown:0
}
}
RESULTS[e].total +=1
RESULTS[e][speakerInfo.gender] +=1
})
console.log(RESULTS);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment