Skip to content

KamKubicki/FVMerger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

FVMerger

Automated invoice download and processing system for Gmail. The script downloads invoices from email attachments, converts images to PDF, and organizes files for sending to the accountant.

✨ Features

  • πŸ—“οΈ Configurable periods - previous month, current month, entire year, or custom range
  • πŸ“„ PDF and JPG support - automatic conversion of invoice photos to PDF
  • πŸ“ Smart file naming - automatic naming with date and sender
  • πŸ“Š Collective preview - single PDF file for quick review of all invoices
  • πŸ” Detailed logging - complete information about the download process
  • βš™οΈ Easy configuration - all settings in config.py file

πŸ“‹ Requirements

  • Python 3.7+
  • Gmail account with API enabled
  • Internet access

πŸš€ Installation

1. Clone repository

git clone <repository-url>
cd FVMerger

2. Create virtual environment (recommended)

python -m venv venv

# Windows
venv\Scripts\activate

# macOS/Linux
source venv/bin/activate

3. Install dependencies

pip install -r requirements.txt

4. Gmail API Configuration

Step 1: Enable Gmail API

  1. Go to Google Cloud Console
  2. Create a new project or select existing one
  3. Enable Gmail API
  4. Go to "Credentials" β†’ "Create Credentials" β†’ "OAuth 2.0 Client IDs"
  5. Select "Desktop application"
  6. Download JSON file and save as client_secret.json in project directory

Step 2: First run

python main.py

On first run, you'll be redirected to browser for Gmail access authorization.

πŸ“– Usage

Basic commands

# Default - previous month (perfect for sending to accountant by 10th of each month)
python main.py

# Current month
python main.py --period current_month

# Entire year
python main.py --period year

# Custom date range
python main.py --period custom --from 2025/01/01 --to 2025/03/31

# Help
python main.py --help

Available periods

Period Description Example usage
last_month Previous month (default) Sending invoices to accountant
current_month Current month Checking invoices during the month
year Entire year Annual summary
custom Custom range Specific billing period

βš™οΈ Configuration

Edit config.py file to customize settings:

# Default download period
DEFAULT_PERIOD = "last_month"

# Directories
TEMP_DIR = "attachments"
JPG_TEMP = "jpg_temp"

# Gmail
CLIENT_SECRET_FILE = "client_secret.json"

# Message filters
EMAIL_FILTER = "-is:starred"

πŸ“ File structure

FVMerger/
β”œβ”€β”€ main.py              # Main script
β”œβ”€β”€ config.py            # Configuration
β”œβ”€β”€ requirements.txt     # Python dependencies
β”œβ”€β”€ README.md           # This documentation
β”œβ”€β”€ client_secret.json  # Gmail API keys (you must add)
β”œβ”€β”€ attachments/        # Downloaded invoices (separate files)
β”‚   β”œβ”€β”€ 2025-07-15_orlen_Invoice_F_1498K19.pdf
β”‚   └── 2025-08-12_siemens_statement_invoice.pdf
β”œβ”€β”€ jpg_temp/          # Temporary files (automatically cleaned)
└── attachments.pdf    # Collective PDF for preview

πŸ“‹ Usage examples

Monthly accountant routine

# At the beginning of the month, download invoices from previous month
python main.py

# Check collective file
# β†’ attachments.pdf

# Send separate files from attachments/ directory to accountant

Check invoices during the month

python main.py --period current_month

Annual summary

python main.py --period year

Specific period (e.g., quarter)

python main.py --period custom --from 2025/01/01 --to 2025/03/31

πŸ”§ Troubleshooting

Gmail authorization issues

# Remove old token and authorize again
rm gmail_token.json
python main.py

"No module named..." error

# Check if virtual environment is active
pip install -r requirements.txt

No invoices found

  • Check if email contains PDF/JPG attachments
  • Check filters in config.py (EMAIL_FILTER)
  • Check date range

JPG conversion issues

  • Make sure JPG files are not corrupted
  • Check if you have enough disk space

πŸ“Š Example output

2025-08-15 23:12:19,716 - INFO - Period: last_month
2025-08-15 23:12:19,716 - INFO - Searching messages from: 2025/07/01 to: 2025/08/01
2025-08-15 23:12:19,716 - INFO - Found 4 messages
2025-08-15 23:12:19,716 - INFO - Processing message 1 from ORLEN PAY <orlenpay@orlen.pl>
2025-08-15 23:12:19,716 - INFO - Saved PDF: 2025-07-15_orlenpay_Invoice_F_1920K19.pdf
...

Hello, I'm sending the following documents in the attachment:

	1. 2025-07-15_orlenpay_Invoice_F_1920K19_0980_25_Orlen_Pay.pdf
	2. 2025-08-12_siemens_2025-08-12_INVOICES_01849_08_25_SLMLO_256131.pdf

Best regards
Kamil Kubicki

--- SUMMARY ---
Period: last_month (2025/07/01 - 2025/08/01)
Files found: 2
Files are located in directory: attachments/
Collective PDF (for preview): attachments.pdf

🀝 Support

In case of problems:

  1. Check "Troubleshooting" section
  2. Run with --help to see all options
  3. Check logs in console

πŸ“„ License

Project for personal use.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors