What it's for
A 300-line bank statement tells you nothing until it is sorted. This script puts each line into a category using keywords you define, then totals by category and by month, and shows what remains unclassified so you can complete your rules.
Before you start
- A CSV export from your bank with
date,labelandamount(negative for an expense). - A JSON rules file:
{ "Transport": ["uber", "fuel"], "Software": ["github", "notion"] }.
Step by step
- Run:
node scripts/30-expense-categorizer.mjs samples/depenses.csv --rules samples/regles.json --out sorted.csv - Look at the "Non classé" lines and add keywords to the rules file.
- Run again until the unclassified part is marginal.
Reading the output
Totals per category (biggest spending first), then per month. Keywords ignore case and accents. Rule order matters: the first category with a keyword found in the label wins.
Automating it
Each month, drop in the new export and re-run: your rules grow richer over time. The --out file reopens in a spreadsheet.
Pitfalls
- A keyword that is too short ("bar") catches far too much: prefer distinctive fragments.
- Your statements are sensitive data: keep them out of public repositories.