-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (33 loc) · 908 Bytes
/
index.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
const fs = require("fs");
const filePath = "./daily_14.json";
fs.readFile(filePath, "utf8", function (err, data) {
if (err) {
console.log("Error: ", err);
throw err;
} else {
try {
const lines = data.split(/\r?\n/);
const cities = [];
lines.forEach((line) => {
if (line) {
const cityObj = JSON.parse(line);
if (cityObj.city.id && cityObj.city.name) {
cities.push({ id: cityObj.city.id, name: cityObj.city.name });
}
}
});
cities.sort((city1, city2) => {
return city1.name.toLowerCase().localeCompare(city2.name.toLowerCase());
});
fs.writeFile("./daily.json", JSON.stringify(cities), (err) => {
if (err) {
throw err;
} else {
console.log("File created");
}
});
} catch (err) {
console.log("Error: ", err);
}
}
});