Skip to content

micklynch/lunchmoney_compare

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

Due to Mint.com closing, I transition to Lunchmoney.app for tracking my spending and managing budgets. One feature I missed from Mint was the chart which showed how I was tracking compared to the previous month. As Lunchmoney has shared an API, I created my own script to generate a similar chart.

Set-up

Create a file called .env in the root folder of this project. The variables included should be:

LM_API_KEY="xyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyz"
LM_HOSTNAME="https://dev.lunchmoney.app"

You can get an API key from lunchmoney.

Installing dependencies

This project uses uv for dependency management. To install dependencies:

uv sync

To also install development dependencies:

uv sync --group dev

Running the code

You can run the code using:

uv run python comparison.py

The script also accepts an optional date argument to specify the reference date for the comparison. If omitted, it defaults to the current date.

  • --date or -d: Specify a date in YYYY-MM-DD format.

Example:

uv run python comparison.py --date 2023-11-15

Alternatively, you can activate the virtual environment first and run normally:

source .venv/bin/activate
python comparison.py

This will generate a comparison as of November 15, 2023, comparing spending up to that day against the equivalent period in October 2023.

How it Works

The script fetches your transactions for two periods:

  1. The "current" period: This starts from the first day of the month of the reference date (either the date provided via --date or today's date if no argument is given) and includes all transactions up to and including the reference date.
  2. The "previous" period: This covers the entire month immediately preceding the reference date's month.

It then calculates cumulative spending for both periods and plots them. The comparison text ("X more/less than last month") is determined by comparing the total spending up to the reference day in the "current" period against a proportionally equivalent day in the "previous" period.

Result

The final graph provides a visual comparison of cumulative spending. An example is shown below (note: your specific output will vary).

lunchmoney_compare_example

Note on the plot:

  • The solid green line shows your spending in the current reference month up to the specified (or current) date.
  • The dashed blue line shows your spending throughout the entire previous month.
  • A dotted green line may also appear, showing "Projected Spending" for the remainder of the current reference month. This projection is based on transactions already made within that month that occur after the reference date.

Potential Improvements:

  • Further refinement of x-axis alignment and labeling for clarity, especially when comparing months of different lengths.

About

Playing around with the Lunchmoney API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages