-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathparser.js
46 lines (36 loc) · 970 Bytes
/
parser.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
const fs = require("fs");
const _ = require("lodash");
async function main() {
try {
const extractedData = [];
const countriesData = [];
const processedData = {};
const rawData = await fs.promises.readFile("./raw.txt", "utf8");
const rawLines = rawData.split("\n");
for (const i of rawLines) {
const lineData = i.split("\t");
const countryCode = i.split(".")[0];
const adminRegion = lineData[1];
countriesData.push(countryCode);
extractedData.push({
c: countryCode,
a: adminRegion,
});
}
for (const i of _.uniq(countriesData)) {
processedData[i] = [];
}
for (const i of extractedData) {
processedData[i.c].push(i.a);
}
for (const country in processedData) {
await fs.promises.writeFile(
`./api/${country}.json`,
JSON.stringify(processedData[country])
);
}
} catch (error) {
console.log(error);
}
}
main();