-
Notifications
You must be signed in to change notification settings - Fork 0
/
process_data.js
103 lines (76 loc) · 2.11 KB
/
process_data.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
101
102
103
const express = require('express');
const app = express();
const fs = require('fs');
const stosMap = require('./sto_kh_all_obj.json');
const stosKh = require('./sto_kh_all.json');
const processServices = () => {
servicesList = [];
stosKh.forEach((sto) => {
let stoDetails = getDetails(sto);
if (stoDetails.services.length) {
servicesList.push(...stoDetails.services);
}
});
console.log('unprocessed services ', servicesList.length);
let uniq = servicesList.filter((value, index, self) => {
return self.indexOf(value) === index;
});
console.log('uniq services ', uniq.length);
fs.writeFile(`./services_list.json`, JSON.stringify(uniq), (err) => {
if (err) {
console.error(err);
return;
};
console.log('Finished Writing Services...');
});
};
const processBrands = () => {
brandsList = [];
stosKh.forEach((sto) => {
let stoDetails = getDetails(sto);
if (stoDetails.brands.length) {
brandsList.push(...stoDetails.brands);
}
});
console.log('unprocessed brands ', brandsList.length);
let uniq = brandsList.filter((value, index, self) => {
return self.indexOf(value) === index;
});
console.log('uniq brands ', uniq.length);
fs.writeFile(`./brands_list.json`, JSON.stringify(uniq), (err) => {
if (err) {
console.error(err);
return;
};
console.log('Finished Writing Brands...');
});
};
const getServiceTypes = () => {
serviceTypesList = [];
stosKh.forEach((sto) => {
if (sto.service_type) {
serviceTypesList.push(sto.service_type);
}
});
let uniq = serviceTypesList.filter((value, index, self) => {
return self.indexOf(value) === index;
});
console.log('uniq service types ', uniq);
fs.writeFile('./service_types_list.json', JSON.stringify(uniq), (err) => {
if (err) {
console.error(err);
return;
};
console.log('Finished Writing Service Types List...');
});
};
const getDetails = (sto) => {
return JSON.parse(fs.readFileSync(`${__dirname}/details/${sto.id}.json`, 'utf8'));
};
const port = 7778;
app.listen(port, () => {
console.log(`SERVER STARTED ON PORT ${port}...`);
// processBrands();
// processServices();
getServiceTypes();
});