Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure folderPath exists #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 12 additions & 4 deletions load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -718,8 +718,16 @@ async function load() {
"tt0258000",
];

// Create the folder if it doesn't exist
const folderPath = "./data/imdb";
const imdbFolderExists = await fs
.stat(folderPath)
.then(() => true)
.catch(() => false);
if (!imdbFolderExists) await fs.mkdir(folderPath);

for (const id of ids) {
const path = `./data/imdb/${id}.html`;
const path = `${folderPath}/${id}.html`;
const exists = await fs
.stat(path)
.then(() => true)
Expand Down Expand Up @@ -762,7 +770,7 @@ async function load() {
const year = parseInt(
$("title")
.text()
.match(/\((\d+)\)/)?.[1] || "0",
.match(/\((\d+)\)/)?.[1] || "0"
);
const title = $("[data-testid=subtitle]").text().trim();
const summary = $("[data-testid=sub-section-summaries] li:first-child")
Expand All @@ -783,7 +791,7 @@ async function load() {
Key: "posters/" + id + ".jpg",
ContentType: "image/jpeg",
Body: await fetch(poster).then((res) => res.arrayBuffer() as any),
}),
})
);

await vector.remove({
Expand Down Expand Up @@ -830,7 +838,7 @@ async function load() {
year,
}),
},
}),
})
);
console.log("Finished", ++index);
});
Expand Down