aboutsummaryrefslogtreecommitdiff
path: root/e621/csv2json.js
blob: ee55fdb17192afca1b65c7ca1bd667e1881cdb32 (plain)
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
const { parse } = require("csv-parse");
const fs = require('fs');

let tags = [];
let aliases = [];

fs.createReadStream("./tags.csv")
    .pipe(parse({ delimiter: ",", from_line: 2 }))
    .on("data", (row) => {
        tags.push({
            id: parseInt(row[0]),
            name: row[1],
            category: parseInt(row[2]),
            postCount: parseInt(row[3])
        });
    })
    .on("end", () => {
        fs.writeFileSync("./tags.json", JSON.stringify(tags));
    });

fs.createReadStream("./tag_aliases.csv")
    .pipe(parse({ delimiter: ",", from_line: 2 }))
    .on("data", (row) => {
        aliases.push({
            id: parseInt(row[0]),
            antecedentName: row[1],
            consequentName: row[2],
            createdAt: new Date(row[3]),
            status: row[4]
        });
    })
    .on("end", () => {
        fs.writeFileSync("./tag_aliases.json", JSON.stringify(aliases));
    });