-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake.js
More file actions
25 lines (23 loc) · 992 Bytes
/
make.js
File metadata and controls
25 lines (23 loc) · 992 Bytes
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
import { writeFile } from "fs/promises";
async function makeJSON(URL, name) {
await fetch(URL)
.then(response => response.text())
.then(async text => {
await writeFile(`database/CSV/${name}.csv`, text);
const entries = text.replace(/["]/g, '').split("\n");
const headers = entries[0].split(",");
const finalJSON = [];
for (let i = 0; i < entries.length; i++) {
const entry = entries[i].split(",");
if (entry.length === headers.length) {
const data = {};
for (let j = 0; j < headers.length; j++) {
data[headers[j]] = entry[j];
}
finalJSON.push(data);
}
}
await writeFile(`database/JSON/${name}.json`, JSON.stringify(finalJSON));
});
}
await makeJSON("https://privacyrights.org/data-brokers/export?page&_format=csv", "brokers");