AI-powered Expense Tracker: automates expense tracking by fetching notes from Google Keep, categorizing expenses using AI (Llama 3), and exporting to Google Sheets. Simplify your monthly budgeting with minimal effort!
- Create a new Google Keep note on the first day of the month. Use a consistent naming convention (e.g., "01-january", "02-february").
- Throughout the month, add your expenses to the note in this format:
20 hairdresser 48 clothes 10 groceries - At the end of the month, run this script to categorize and export your expenses to Google Sheets.
- Python 3.x
- Docker (for obtaining Google tokens)
- Ollama (for automatic expense categorization)
- Clone the repository:
git clone https://github.com/sofiabaezzato/simple-expense-tracker.git cd expense-tracker - Create and activate a virtual environment:
- On Windows, in Powershell:
python -m venv venv .\venv\Scripts\activate - On macOS/Linux:
python -m venv venv source venv/bin/activate
- On Windows, in Powershell:
- Install dependencies:
pip install -r requirements.txt - Set up your .env file with the required tokens (see "How to get Google tokens" below).
-
Obtain your Google OAuth token:
- Visit this Google page
- Sign in with your Google credentials
- Click "I agree" when prompted
- Inspect the page > Application > Cookies > Copy the
oauthtoken
-
Use Docker to generate your master token:
docker run --rm -it python:3 /bin/bash -c "pip install gpsoauth && python3 -c \"import gpsoauth; print(gpsoauth.exchange_token(input('Email: '), input('OAuth Token: '), input('Android ID: ')))\""- Enter your Google Keep email, OAuth token, and a randomly generated 16-digits hexadecimal Android ID when prompted
- The resulting
aas_et/token is your master token
-
Add your Google Keep email and your master token to your .env file:
GKEEP_EMAIL=your_oauth_token_here MASTER_TOKEN=your_master_token_here
- Create a new project in Google Cloud Console
- Enable API and services in the project dashboard
- Enable Google Sheets API and create credentials (make sure to grant Editor access to the account)
- Create and download the keys file
- Import the keys file in your project folder and name it
g-sheets-credentials.json - Share the Google Sheet with the Service Account previously created
- Add the sheet id (
SHEET_ID) you want to write on in the.envfile
- Install Ollama
- Pull the Llama 3 model:
ollama pull llama3 - Start the Ollama service:
ollama serve
- Ensure your virtual environment is activated
- Make a copy of the
TEMPLATEsheet in your worksheet and give it the name of the month as a title - Run the script:
python init.py - Enter the title of your Google Keep note and the title of the sheet when prompted
Note: you can also run read_keep.py and write_sheets.py individually for testing purposes.
You can customize expense categories by editing the categories.yaml file in the project root. You can also edit the AI prompt in the prompt_template.txt file.
If you encounter any issues, please check the following:
- Ensure all tokens in your .env file are correct and up to date. Your
envfile should look like this:MASTER_TOKEN=<your master token> GKEEP_EMAIL=<your Google Keep email> SHEET_ID=<id of your Google Sheet> - Verify that Ollama is running and the Llama3 model is installed
For further assistance, please open an issue on the GitHub repository.
Please feel free to submit a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.