-
Notifications
You must be signed in to change notification settings - Fork 1
/
data-ptime-en.js
51 lines (46 loc) · 1.22 KB
/
data-ptime-en.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
import { readJSON, writeCSV } from "https://deno.land/x/[email protected]/mod.ts";
const filename = Deno.args[0];
const data = await readJSON(filename);
const output = [];
for (const type in data) {
output.push({ type, ...data[type] });
}
const newfile = filename.replace(".json", ".csv");
await writeCSV(newfile, output);
const flatObject = (obj) =>
Object.keys(obj)
.map((key) => {
return `${key}: ${obj[key]}`;
})
.join(" / ");
const formate = (keysMap, obj) =>
Object.keys(obj).reduce(
(acc, key) => ({
...acc,
...{
[keysMap[key] || key]:
typeof obj[key] === "string"
? obj[key].replace("No processing time available", "")
: flatObject(obj[key]),
},
}),
{}
);
const country = (await readJSON("data-country-name-en.json"))["country-name"];
const formattedOutput = output.map((row) => formate(country, row));
await writeCSV(`formatted-${newfile}`, formattedOutput);
const formattedSelectedOutput = output.map(
({ type, WB, JO, TR, IL, lastupdated }) =>
formate(country, {
type,
WB,
JO,
TR,
IL,
lastupdated,
})
);
await writeCSV(
`formatted-selected-countries-${newfile}`,
formattedSelectedOutput
);