Skip to content

Instantly share code, notes, and snippets.

@apocas
Last active August 29, 2015 14:02
Show Gist options
  • Save apocas/51d15100ee882fda5f92 to your computer and use it in GitHub Desktop.
Save apocas/51d15100ee882fda5f92 to your computer and use it in GitHub Desktop.
LXJS 2014 CSV Workshops Importer
var csv = require('ya-csv'),
github = require('octonode');
var client = github.client({
username: 'apocas',
password: 'xxxxxxxx'
});
var reader = csv.createCsvFileReader('lxjs.csv', {'columnsFromHeader':true, 'separator': ','});
var workshops = {
'level': {
'repo': 'https://github.com/LXJS/training-level',
'team': 860544,
'data': {}
},
'iot': {
'repo': 'https://github.com/LXJS/training-iot',
'team': 860545,
'data': {}
},
'hapijs': {
'repo': 'https://github.com/LXJS/training-hapijs',
'team': 860546,
'data': {}
},
'node-webkit': {
'repo': 'https://github.com/LXJS/training-node-webkit',
'team': 860547,
'data': {}
},
'nodebots': {
'repo': 'https://github.com/LXJS/training-nodebots',
'team': 860548,
'data': {}
},
'dtrace': {
'repo': 'https://github.com/LXJS/training-dtrace',
'team': 860549,
'data': {}
},
'koa': {
'repo': 'https://github.com/LXJS/training-koa',
'team': 860550,
'data': {}
},
'webrtc': {
'repo': 'https://github.com/LXJS/training-webrtc',
'team': 860551,
'data': {}
}
};
reader.addListener('data', function(data) {
var name = data['First Name'] + ' ' + data['Last Name'];
if(data['Github Handle'] && data['Github Handle'] != '-') {
var github = data['Github Handle'].trim().replace('https://github.com/', '').replace('@', '');
}
if(data['Twitter handle'] && data['Twitter handle'] != '-') {
var twitter = data['Twitter handle'].trim().replace('@', '');
}
var workshopsi = [];
addSub(workshopsi, data.Workshops1);
addSub(workshopsi, data.Workshops2);
addSub(workshopsi, data.Workshops3);
addSub(workshopsi, data.Workshops4);
for (var i = 0; i < workshopsi.length; i++) {
if(workshops[workshopsi[i].workshop]) {
if(!workshops[workshopsi[i].workshop].data[workshopsi[i].date]) {
workshops[workshopsi[i].workshop].data[workshopsi[i].date] = [];
}
var line = name;
if(github) {
line += ' - [' + github + '](https://github.com/' + github + ')';
addMember(workshopsi[i].workshop, github);
}
if(workshops[workshopsi[i].workshop].data[workshopsi[i].date].indexOf(line) < 0) {
workshops[workshopsi[i].workshop].data[workshopsi[i].date].push(line);
}
} else {
console.log('WTF: ');
console.log(workshopsi[i].workshop);
}
}
});
reader.addListener('end', function() {
//console.log(require('util').inspect(workshops, {'depth': null}));
for (var workshop in workshops) {
if (workshops.hasOwnProperty(workshop)) {
var workshopo = workshops[workshop];
console.log('#######################################');
console.log(workshopo.repo);
console.log('#######################################');
for (var date in workshopo.data) {
if (workshopo.data.hasOwnProperty(date)) {
console.log('');
console.log('## ' + date + 'h Participants');
console.log('');
for (var i = 0; i < workshopo.data[date].length; i++) {
console.log('- ' + workshopo.data[date][i]);
}
}
}
console.log('');
}
}
});
function addSub(workshops, workshop) {
if(workshop != '#N/A' && workshop.trim().length > 0) {
workshops.push({
'workshop': workshop.split(' - ')[2].toLowerCase().trim(),
'date': workshop.split(' - ')[0].toLowerCase().trim() + ' - ' + workshop.split(' - ')[1].toLowerCase().trim()
});
}
}
function addMember(workshop, member) {
console.log('ADDING ' + member + ' TO ' + workshop);
var ghteam = client.team(workshops[workshop].team);
ghteam.addUser(member, function(err, data) {
if(err) {
return console.log('FAILED TO ADD USER ' + member + ' TO WORKSHOP ' + workshop);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment