Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed SWFrontUI/.DS_Store
Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

35 changes: 27 additions & 8 deletions supabase_import.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ const supabase = createClient(SUPABASE_URL, SUPABASE_KEY);
// Used for comma-separated classifiers and semicolon-separated store IDs/prices.
function split(s, sep) {
if (!s) return [];
return s.split(sep).map((x) => x.trim()).filter(Boolean);
return s
.split(sep)
.map((x) => x.trim())
.filter(Boolean);
}

// Returns a float or null — null means the field was empty/unparseable,
Expand Down Expand Up @@ -83,7 +86,10 @@ async function insertBatch(table, rows, dryRun) {
// Rows missing a name or price are skipped since both are NOT NULL in the table.

export async function importWalmart({ dryRun = false } = {}) {
const file = path.join(__dirname, 'WalmartPipeline/classified_ingredients.csv');
const file = path.join(
__dirname,
'WalmartPipeline/classified_ingredients.csv',
);
console.log(`\n Source: ${file}`);

let batch = [];
Expand All @@ -97,7 +103,9 @@ export async function importWalmart({ dryRun = false } = {}) {
await insertBatch(TABLE_WALMART, batch, dryRun);
totalInserted += batch.length;
batch = [];
process.stdout.write(`\r Inserted ${totalInserted.toLocaleString()} rows...`);
process.stdout.write(
`\r Inserted ${totalInserted.toLocaleString()} rows...`,
);
}

for await (const row of csvParser(file)) {
Expand Down Expand Up @@ -133,8 +141,12 @@ export async function importWalmart({ dryRun = false } = {}) {

console.log(`\n Done.`);
console.log(` Inserted : ${totalInserted.toLocaleString()}`);
console.log(` Skipped (not ingredient): ${skippedNonIngredient.toLocaleString()}`);
console.log(` Skipped (no name/price) : ${skippedMissingFields.toLocaleString()}`);
console.log(
` Skipped (not ingredient): ${skippedNonIngredient.toLocaleString()}`,
);
console.log(
` Skipped (no name/price) : ${skippedMissingFields.toLocaleString()}`,
);
}

// ── Kroger ────────────────────────────────────────────────────────────────────
Expand All @@ -144,7 +156,10 @@ export async function importWalmart({ dryRun = false } = {}) {
// and store all the store IDs as an array.

export async function importKroger({ dryRun = false } = {}) {
const file = path.join(__dirname, 'kroger_output/catalogue/food_catalogue.csv');
const file = path.join(
__dirname,
'kroger_output/catalogue/food_catalogue.csv',
);
console.log(`\n Source: ${file}`);

let batch = [];
Expand All @@ -156,7 +171,9 @@ export async function importKroger({ dryRun = false } = {}) {
await insertBatch(TABLE_KROGER, batch, dryRun);
totalInserted += batch.length;
batch = [];
process.stdout.write(`\r Inserted ${totalInserted.toLocaleString()} rows...`);
process.stdout.write(
`\r Inserted ${totalInserted.toLocaleString()} rows...`,
);
}

for await (const row of csvParser(file)) {
Expand Down Expand Up @@ -194,7 +211,9 @@ export async function importKroger({ dryRun = false } = {}) {

console.log(`\n Done.`);
console.log(` Inserted : ${totalInserted.toLocaleString()}`);
console.log(` Skipped (no name/price): ${skippedMissingFields.toLocaleString()}`);
console.log(
` Skipped (no name/price): ${skippedMissingFields.toLocaleString()}`,
);
}

// ── Entry point (when run directly) ──────────────────────────────────────────
Expand Down
Loading