Last active
September 15, 2017 19:13
-
-
Save prpatel/7102890be918a167081c3087541f50d6 to your computer and use it in GitHub Desktop.
change connect.tech standard json to format for ReactNative app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'), | |
_ = require('underscore'), | |
moment = require('moment'); | |
function generateSchedule() { | |
function jsonEscape(str) { | |
return str.replace(/\n/g, "").replace(/\r/g, "").replace(/\t/g, ""); | |
} | |
// from http://cfp.connect-js.com/en/ct2017/public/full_schedule.json | |
var file = fs.readFileSync("data/full_schedule2016.json", "utf8"); | |
file = (JSON.parse(jsonEscape(file))); | |
// breakfast, coffee, lunch, party | |
function scheduleGen() { | |
var schedule = []; | |
_.each(file.schedule.conference.days, function (d) { | |
_.each(d.rooms, function (r, k) { | |
_.each(r, function (session) { | |
s = transformSession(session); | |
// console.log('\n', session) | |
// console.log('\n', s); | |
schedule.push(s) | |
}); | |
}); | |
}); | |
return schedule; | |
} | |
// WARNING SIDE-EFFECT IN PROGRESS | |
function transformSession(s) { | |
var speakerData = []; | |
var timeStart = moment(s.date).format("MM/DD/YYYY hh:mm A"); | |
var speakerNames = _.map(s.persons, function (p) { | |
return p.full_public_name; | |
}); | |
speakerNames = speakerNames.join(','); | |
_.each(s.persons, function (p) { | |
speakerData.push({ | |
"name": p.full_public_name, | |
"image": "http://cfp.connect-js.com" + p.avatar_path, | |
"twitter": p.twitter_name, | |
"bio": p.abstract | |
}); | |
}); | |
var duration = moment.duration(s.duration).asMinutes(); | |
var typeOfsession = "talk"; | |
if (s.type == 'lecture' || s.type == 'workshop') { | |
typeOfsession = "talk"; | |
} else if(s.title.indexOf( 'Lunch') >=0) { | |
typeOfsession = "lunch"; | |
} else if(s.title.indexOf( 'Break')>=0) { | |
typeOfsession = "coffee"; | |
} else if(s.title.indexOf( 'Reception')>=0) { | |
typeOfsession = "party"; | |
} else if(s.title.indexOf( 'Party')>=0) { | |
typeOfsession = "party"; | |
} | |
return { | |
"title": s.title, | |
"location": s.room, | |
"description": s.abstract, | |
"speaker": speakerNames, | |
"time": timeStart, | |
"duration": duration, | |
"speakerInfo": speakerData, | |
"type": typeOfsession, | |
"room": s.track | |
} | |
} | |
var container = { | |
"schedule" : scheduleGen() | |
} | |
// console.log(container) | |
console.log(JSON.stringify(container)) | |
} | |
generateSchedule(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment