Skip to content

Commit

Permalink
Script to populate anime with missing altName
Browse files Browse the repository at this point in the history
  • Loading branch information
rocktimsaikia committed Dec 25, 2024
1 parent d174f94 commit 5cb3244
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"@types/cors": "^2.8.17",
"@types/express": "^4.17.21",
"@types/morgan": "^1.9.9",
"csv-parse": "^5.6.0",
"esbuild": "^0.23.1",
"typescript": "^5.4.5",
"vitest": "^2.0.5"
Expand Down
File renamed without changes.
37 changes: 37 additions & 0 deletions server/scripts/populate-altname.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type { Options } from "csv-parse";
import { parse } from "csv-parse";
import fs from "node:fs";
import { prisma } from "~/libs/prisma";

const options: Options = {
delimiter: ",",
columns: true,
skipEmptyLines: true,
trim: true,
skip_records_with_error: true,
};

const filePath = "../data/anime-with-no-alt-name.csv";

fs.createReadStream(filePath)
.pipe(parse(options))
.on("data", async (row) => {
const data = await prisma.anime.findUnique({
where: {
name: row.name,
},
select: {
id: true,
name: true,
},
});
if (data) {
console.log(data);
}
})
.on("error", (err) => {
console.error("Error:", err);
})
.on("end", () => {
console.log("Finished reading CSV");
});

0 comments on commit 5cb3244

Please sign in to comment.