← back to Sdcc Awards
cypressaward/scraper/insert-twenty-more-awards.js
60 lines
const { createClient } = require('@supabase/supabase-js');
const { twentyMoreCyPresAwards } = require('./twenty-more-cypres-awards');
// Initialize Supabase client
const supabaseUrl = process.env.SUPABASE_URL || 'https://your-project.supabase.co';
const supabaseKey = process.env.SUPABASE_ANON_KEY || 'your-anon-key';
const supabase = createClient(supabaseUrl, supabaseKey);
async function insertTwentyMoreAwards() {
console.log('🚀 Starting to insert 20 additional cy pres awards...');
console.log(`📊 Total awards to insert: ${twentyMoreCyPresAwards.length}`);
let successCount = 0;
let errorCount = 0;
let duplicateCount = 0;
for (const award of twentyMoreCyPresAwards) {
try {
// Check if award already exists by hash
const { data: existing } = await supabase
.from('scraped_awards')
.select('id')
.eq('hash', award.hash)
.single();
if (existing) {
console.log(`⚠️ Duplicate: ${award.recipient_organization} - ${award.case_name}`);
duplicateCount++;
continue;
}
// Insert the award
const { error } = await supabase
.from('scraped_awards')
.insert(award);
if (error) {
console.error(`❌ Error inserting ${award.recipient_organization}:`, error.message);
errorCount++;
} else {
console.log(`✅ Inserted: ${award.recipient_organization} - ${award.amount_text}`);
successCount++;
}
} catch (error) {
console.error(`❌ Unexpected error for ${award.recipient_organization}:`, error);
errorCount++;
}
}
console.log('\n📈 Final Results:');
console.log(`✅ Successfully inserted: ${successCount} awards`);
console.log(`⚠️ Duplicates skipped: ${duplicateCount} awards`);
console.log(`❌ Errors: ${errorCount} awards`);
const totalAmount = twentyMoreCyPresAwards.reduce((sum, award) => sum + award.amount, 0);
console.log(`💰 Total amount of new awards: $${totalAmount.toLocaleString()}`);
}
// Run the insertion
insertTwentyMoreAwards().catch(console.error);