Last active
August 29, 2015 14:05
-
-
Save nickleefly/61056c41407b9de5b2af to your computer and use it in GitHub Desktop.
writeStream create data
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 GraphModel = require('../models/graphModel.js'); | |
var fs = require('fs'); | |
var moment = require('moment'); | |
/** | |
Provides the controllers for the application views | |
@module api/controllers | |
**/ | |
exports.controller = function(req, res) { | |
var graphModel = new GraphModel(); | |
graphModel.GetData(function(err, model){ | |
model.title = graphModel.title; | |
model.listing = graphModel.listing; | |
fs.exists('public/stream-data.csv', function(exists) { | |
if (exists) { | |
// return res.send(model) | |
res.render('graph.ejs') | |
} else { | |
var wstream = fs.createWriteStream('public/stream-data.csv'); | |
wstream.write('id,year,Film,Rating,Genre,zipcode\n'); | |
for (var i = 0; i < graphModel.listing.length; i ++) { | |
var item = graphModel.listing[i]; | |
var listingData = item.id + ',' + | |
moment(item.release_date).format('YYYY') + ',' + | |
item.movie_title + ',' + | |
item.rating + ',' + | |
item.genre + ',' + | |
item.postalCode + '\n'; | |
wstream.write(listingData); | |
} | |
wstream.end(); | |
} | |
}) | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment