-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert_brewery_xml_to_js.js
66 lines (55 loc) · 1.89 KB
/
convert_brewery_xml_to_js.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
var fs = require('fs');
var xml2js = require('xml2js');
var parser = new xml2js.Parser();
var all_beer;
var breweries = [];
fs.readFile('./breweries_from_api_chars.xml', function(err, data) {
if (err) {
console.log(err);
} else {
parser.parseString(data, function (err, result) {
if (err) {
console.log(err);
} else {
all_beer = (result.bmp_locations.location);
// create address key
all_beer["address"] = undefined;
for (i = 0; i < all_beer.length; i++) {
// strip arrays wrapping each value
all_beer[i].name = all_beer[i].name[0];
all_beer[i].status = all_beer[i].status[0];
all_beer[i].street = all_beer[i].street[0];
all_beer[i].city = all_beer[i].city[0];
all_beer[i].state = all_beer[i].state[0];
all_beer[i].zip = all_beer[i].zip[0];
// remove unwanted keys
delete all_beer[i].id;
delete all_beer[i].reviewlink;
delete all_beer[i].proxylink;
delete all_beer[i].blogmap;
delete all_beer[i].country;
delete all_beer[i].phone;
delete all_beer[i].overall;
delete all_beer[i].imagecount;
// remove non-breweries
if (all_beer[i].status === "Brewery") {
delete all_beer[i].status;
// compile address
all_beer[i].address = all_beer[i].street + ", " + all_beer[i].city + ", " + all_beer[i].state + " " + all_beer[i].zip;
breweries.push(all_beer[i]);
}
}
console.log(breweries.length);
console.log(breweries[0]);
fs.writeFile('breweries_and_loc.json', JSON.stringify(breweries, null, 2), function(err) {
if (err) {
console.log(err);
} else {
console.log("File written!");
}
});
console.log('Done.');
}
});
}
});