-
Notifications
You must be signed in to change notification settings - Fork 0
/
texecute.js
74 lines (68 loc) · 1.79 KB
/
texecute.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
// Add modules
var request = require('request');
var $ = require('cheerio');
var fs = require('fs');
// State of Texas executed list
var url = 'http://www.tdcj.state.tx.us/death_row/dr_executed_offenders.html';
function Inmate() {
};
function parseRows(url, done) {
request(url, function(err, res, html) {
if (err) return log(err);
var parsedHtml = $.load(html);
var json = [];
parsedHtml('tr').map(function(i, elem) {
if (i > 0) {
var row = elem.children.filter(function(d) { return d.type === 'tag' });
var inmate = new Inmate;
row.forEach(function(item, index, arr) {
var len = arr.length;
attrInmate(index, item, inmate, function(d) {
json.push(d);
});
});
}
}).end(done(json));
});
}
function attrInmate(index, attr, inmate, done) {
if (index === 0) {
inmate.execution = attr.children[0].data;
}
if (index === 3) {
inmate.lastName = attr.children[0].data;
}
if (index === 4) {
inmate.firstName = attr.children[0].data;
}
if (index === 5) {
inmate.tdcjNumber = attr.children[0].data;
}
if (index === 6) {
inmate.age = attr.children[0].data;
}
if (index === 7) {
inmate.executionDate = attr.children[0].data;
}
if (index === 8) {
inmate.race = attr.children[0].data;
}
if (index === 9) {
inmate.county = attr.children[0].data;
done(inmate)
}
}
function log() {
var args = Array.prototype.slice.call(arguments);
args.forEach(function(item) {
console.log(item)
})
}
// parseRows('http://www.tdcj.state.tx.us/death_row/dr_info/villegasjoselast.html')
parseRows(url, function(json) {
var data = JSON.stringify(json, null, 2);
fs.writeFile('./executed.json', data, function(err) {
if (err) return log(err);
log('Finished')
})
});