-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
100 lines (82 loc) · 2.85 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
var express = require('express');
var fs = require('fs');
var app = express();
var bodyParser = require('body-parser');
var http = require('http');
app.use(express.static(__dirname + '/'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
// All filenames for student data.
var urls = [
'Austin_Scott.json',
'Brendon_Pierson.json',
'Brittney_Corona.json',
'Caitlin_Stein.json',
'Dan_Hodges.json',
'danielcossins.json',
'Deric_Bunch.json',
'Jeremy_Grondahl.json',
'Jesse_Turner.json',
'Juan_Rodriguez.json',
'Lynn_Samuelson.json',
'Mary_Kergosien.json',
'Peter_Connolly.json',
'Rachel_Morgan.json',
'Richard_Aites.json',
'Robin_Burton.json',
'Ryan_Tanay.json',
'Sally_Fisher.json',
'Seth_Dorris.json',
'Shelley_DavisWise.json',
'Tom_Griffey.json',
'Wayne_Hutchinson.json'
];
var finalJson = {students: []};
for (var i=0; i < urls.length; i++) {
url = '_students/' + urls[i];
fs.readFile(url, 'utf8', function (err, data) {
if (err) {
return console.log(err);
}
console.log(data);
data = JSON.parse(data);
finalJson.students.push(data);
});
}
setTimeout(function () {
fs.writeFile('all_students.json', JSON.stringify(finalJson, null, 4), function (err) {
console.log("File written");
});
}, 5000)
setTimeout(function () {
fs.readFile('all_students.json', 'utf8', function (err,data) {
if (err) {
return console.log(err);
}
var parsedData = JSON.parse(data);
//console.log(parsedData.students);
var htmlData = "";
for (var i=0; i < parsedData.students.length; i++) {
htmlData += "<li class='student-list'>" + "\n" + " " +
"<div class='profile-cell'>" + "\n" + " " +
"<a class='studentlink' href='" + parsedData.students[i].site.toString() + "' target='_blank'>" + "\n" + " " +
"<div class='crop'>" + "\n" + " " +
"<img class='student-pic' mouseover-src='images/2015_12_02_NSS_" + parsedData.students[i].imageProp.toString() + "_T.jpg' src='images/2015_12_02_NSS_" + parsedData.students[i].image.toString() + "_T_BW.jpg'>" + "\n" + " " +
"</div>" + "\n" + " " +
"<h6 class='student-name'>" + parsedData.students[i].name.toString() + "</h6>" + "\n" + " " +
"</a>" + "\n" + " " +
"<span class='student-bio'>" + parsedData.students[i].bio.toString() + "</span>" + "\n" + " " +
"</div>" + "\n" +
"</li>" + "\n"
}
console.log(htmlData);
fs.writeFile('students.html', htmlData, 'utf8', function (data) {
console.log(data);
});
});
}, 10000)
app.listen('8081')
console.log('Magic happens on port 8081');
exports = module.exports = app;