diff --git a/src/features/codante-apis/senator-expenses/summaries/updatePartySummary.ts b/src/features/codante-apis/senator-expenses/summaries/updatePartySummary.ts index 7ce4933..e0ba06b 100644 --- a/src/features/codante-apis/senator-expenses/summaries/updatePartySummary.ts +++ b/src/features/codante-apis/senator-expenses/summaries/updatePartySummary.ts @@ -37,8 +37,10 @@ export async function updatePartySummary(year: number) { const sanitized = expensesByParty.map((row) => { return { party: row.party, - total_expenses: row.total, - total_per_senator: row.total / groupedByParty[row.party].length, + total_expenses: parseFloat(Number(row.total)?.toFixed(2)), + total_per_senator: parseFloat( + (row.total / groupedByParty[row.party].length).toFixed(2) + ), senator_ids: groupedByParty[row.party], }; }); diff --git a/src/features/codante-apis/senator-expenses/summaries/updateUFSummary.ts b/src/features/codante-apis/senator-expenses/summaries/updateUFSummary.ts index 9487473..8cfc7ae 100644 --- a/src/features/codante-apis/senator-expenses/summaries/updateUFSummary.ts +++ b/src/features/codante-apis/senator-expenses/summaries/updateUFSummary.ts @@ -15,6 +15,13 @@ export async function updateUFSummary(year: number) { .groupBy(expenses.uf); // get unique parties from the expenses table + const sanitized = data.map((row) => { + return { + uf: row.uf, + total_expenses: parseFloat(Number(row.total)?.toFixed(2)), + }; + }); + await db .delete(summaries) .where(and(eq(summaries.year, year.toString()), eq(summaries.type, 'uf'))); @@ -22,6 +29,6 @@ export async function updateUFSummary(year: number) { await db.insert(summaries).values({ type: 'uf', year: year.toString(), - summary: data, + summary: sanitized, }); } diff --git a/src/features/codante-apis/senator-expenses/updater.ts b/src/features/codante-apis/senator-expenses/updater.ts index 123651f..a78a01c 100644 --- a/src/features/codante-apis/senator-expenses/updater.ts +++ b/src/features/codante-apis/senator-expenses/updater.ts @@ -2,12 +2,14 @@ import { scrapeExpenses } from './expenses/scrapeExpenses'; import { updatePartySummary } from './summaries/updatePartySummary'; import { updateUFSummary } from './summaries/updateUFSummary'; +updater(); + export async function updater() { const YEAR = 2024; // update expenses console.log('Scraping expenses...'); - await scrapeExpenses(YEAR); + // await scrapeExpenses(YEAR); // update summaries console.log('Updating party summary...'); diff --git a/src/scheduler/index.ts b/src/scheduler/index.ts index 66f3867..9cc690a 100644 --- a/src/scheduler/index.ts +++ b/src/scheduler/index.ts @@ -1,7 +1,12 @@ import { Cron } from 'croner'; import { updater } from '../features/codante-apis/senator-expenses/updater'; -const job = Cron('0 2 * * *', async () => { +// const job = Cron('0 2 * * *', async () => { +// console.log('Running '); +// await updater(); +// }); + +const job = Cron('* * * * *', async () => { console.log('Running '); await updater(); });