39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
import moment from "moment";
|
|
import { Enums, prisma } from "#lib/server/prisma.js";
|
|
import * as fs from "fs";
|
|
import { fileURLToPath } from "url";
|
|
import { hashPassword } from "#lib/password.js";
|
|
import Papa from "papaparse";
|
|
import { generatePrefixedId } from "#lib/db.js";
|
|
import { VALID_UUID_PREFIXES } from "#lib/constants.js";
|
|
import { tryCatch } from "#lib/tryCatch.js";
|
|
import { createBrotliDecompress } from "zlib";
|
|
|
|
const path = fileURLToPath(new URL("./ausweise.csv.br", import.meta.url)); // .br for Brotli file
|
|
|
|
if (!fs.existsSync(path)) {
|
|
throw new Error(`${path} existiert nicht.`);
|
|
}
|
|
|
|
let i = 0;
|
|
const brotliStream = fs.createReadStream(path).pipe(createBrotliDecompress());
|
|
|
|
Papa.parse(brotliStream, {
|
|
header: true,
|
|
async complete(results, file) {
|
|
for (const dataset of results.data as any) {
|
|
const existing = await prisma.verbrauchsausweisWohnen.findFirst({
|
|
where: {
|
|
alte_ausweis_id: parseInt(dataset.id)
|
|
}
|
|
});
|
|
|
|
if (existing) {
|
|
continue;
|
|
}
|
|
|
|
console.log(dataset.id);
|
|
// do something with dataset...
|
|
}
|
|
},
|
|
}); |