-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnieman.js
56 lines (54 loc) · 1.87 KB
/
nieman.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
var fs = require('fs');
var assert = require('assert');
var csv = require('csv-parser');
var json2csv = require('json2csv');
var list = [];
fs.createReadStream('nieman-fellows.csv')
.pipe(csv())
.on('data', function(fellow){
fs.createReadStream('winners.csv')
.pipe(csv())
.on('data', function(prize){
for (var field in prize){
//checks to see if last name and either given or perferred name matches any fields in the prize list
if (prize[field].search(fellow.LAST) != -1 && prize[field].search(fellow.FIRST) != -1) {
prize.fellow = fellow['FULL NAME'];
prize.NF = fellow.YEAR;
json2csv({data: prize}, function(err, csv){
if (err) {
console.log(err);
}
csv = csv.replace('"category","year","type","title","publication","citation","fellow","NF"', '');
csv = csv.replace('\\n', '');
fs.appendFile('nieman-winners.csv', csv, function (err){
console.log('Found winner: ' + fellow['FULL NAME']);
if(err) throw err;
});
});
}
}
});
fs.createReadStream('finalists.csv')
.pipe(csv())
.on('data', function(prize){
for (var field in prize){
//checks to see if last name and either given or perferred name matches any fields in the prize list
if (prize[field].search(fellow.LAST) != -1 && prize[field].search(fellow.FIRST) != -1) {
prize.fellow = fellow['FULL NAME'];
prize.NF = fellow.YEAR;
json2csv({data: prize}, function(err, csv){
if (err) {
console.log(err);
}
csv = csv.replace('"category","year","type","title","publication","citation","fellow","NF"', '');
csv = csv.replace('\\n', '');
console.log(csv);
fs.appendFile('nieman-finalists.csv', csv, function (err){
console.log('Found finalist: ' + fellow['FULL NAME']);
if(err) throw err;
});
});
}
}
});
});