Skip to content

Instantly share code, notes, and snippets.

@henry-thompson
Last active January 18, 2018 14:49
Show Gist options
  • Save henry-thompson/b43c99046b9b26a407909989d0a98eb4 to your computer and use it in GitHub Desktop.
Save henry-thompson/b43c99046b9b26a407909989d0a98eb4 to your computer and use it in GitHub Desktop.
Converts the sponsors' attendees' information in the Hack Cambridge Sponsors' Portal to a CSV digestible by the Gavel hackathon expo judging system's user entry method
// Converts a dump of the Firebase database from the Hack Cambridge Sponsors'
// portal into a CSV compatible with the Gavel hackathon judging system
if (!process.argv[2]) {
return console.log('Provide input JSON filename');
}
var fs = require('fs');
var data = JSON.parse(fs.readFileSync(process.argv[2], 'utf8'));
var sponsors = data.sponsors;
var csv = "";
for (var guid in sponsors) {
var people = sponsors[guid].people;
if (people && people.mentors) {
for (var mentor of people.mentors) {
if (mentor) {
csv += '"' + mentor.name + '","' + mentor.email + '","Judge"\n';
}
}
}
if (people && people.recruiters) {
for (var recruiter of people.recruiters) {
if (recruiter) {
csv += '"' + recruiter.name + '","' + recruiter.email + '","Judge"\n';
}
}
}
}
fs.writeFile("gavel.csv", csv, function(err) {
if (err) {
return console.log(err);
}
console.log("The file was saved!");
});
// Converts a dump of the Firebase database from the Hack Cambridge Sponsors'
// portal into a CSV compatible with the HelpQ hackathon ticketing system
if (!process.argv[2]) {
return console.log('Provide input JSON filename');
}
var fs = require('fs');
var data = JSON.parse(fs.readFileSync(process.argv[2], 'utf8'));
var sponsors = data.sponsors;
var csv = "";
for (var guid in sponsors) {
var people = sponsors[guid].people;
var companyName = sponsors[guid].name;
// Accenture and ManAHL were done in advance by Jacob
if (companyName === 'Accenture' || companyName === 'ManAHL') {
continue;
}
// Test company
if (companyName === 'Acme Inc') {
continue;
}
if (people && people.mentors) {
for (var mentor of people.mentors) {
if (mentor) {
csv += getCsv(mentor, companyName);
}
}
}
if (people && people.recruiters) {
for (var recruiter of people.recruiters) {
if (recruiter) {
csv += getCsv(recruiter, companyName);
}
}
}
}
function getCsv(person, companyName) {
var name = person.name;
// Some sponsors entered names as "Lastname, Firstname". Correct this.
var rawName = person.name;
if (rawName.indexOf(',') >= 0) {
var names = rawName.split(',');
rawName = names[1].trim() + " " + names[0].trim();
}
var username = rawName.trim().replace(/(\s|,)+/g, '-').toLowerCase();
var password = Math.random().toString(36).slice(-8);
var displayName = person.name.trim() + " (" + companyName + ")";
return username + ',' + password + ',' + displayName + '\n';
}
fs.writeFile("helpq.csv", csv, function(err) {
if (err) {
return console.log(err);
}
console.log("The file was saved!");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment