Skip to main content

A Python tool that extracts and analyzes food logs from Telegram exports using LLMs

Project description

parsefood

Python License OpenRouter

🍽️ Parse food logs from Telegram and track calories with AI 📊

Quick Start · Features · Documentation


Overview

The Pain: Manually tracking calories from natural-language food notes is tedious, error-prone, and never gets done consistently.

The Solution: parsefood connects to your Telegram, reads your food log messages in Portuguese, and uses LLMs to extract ingredients, match them against a structured nutrition database, and calculate calories automatically.

The Result: Daily calorie trend visualizations and Telegram bot progress reports — with zero manual data entry.

Features

  • AI-Powered Extraction — Uses OpenRouter LLMs (Gemini, GPT, Claude) to parse natural language food entries in Portuguese
  • Structured Food Database — JSON-based nutrition database with per-100g values and unit conversions
  • Calorie Trend Visualization — Polynomial regression plots showing intake patterns over time
  • Telegram Bot Integration — Get daily progress reports with colorful progress bars
  • Multiple Input Methods — Add foods via product label images (vision AI) or web scraping from supermarket URLs
  • Multi-User Profiles — YAML-based profile system for tracking multiple users
  • Automatic Backups — Timestamped backups before any processing

🚀 Quick Start

# Clone and install
git clone https://github.com/tsilva/parsefood.git
cd parsefood
uv sync

# Configure
cp .env.example .env
# Edit .env with your OPENROUTER_API_KEY

# Run
uv run python main.py

View your calorie trend at data/plot.png.

Daily Status

# Quick read-only view of today's progress
uv run python main.py --today

🔧 Installation

Prerequisites

Setup

# Install uv (if needed)
curl -LsSf https://astral.sh/uv/install.sh | sh

# Clone repository
git clone https://github.com/tsilva/parsefood.git
cd parsefood

# Install dependencies
uv sync

# Configure environment
cp .env.example .env

Edit .env with your settings:

MODEL_ID=google/gemini-2.5-flash
OPENROUTER_API_KEY=your_api_key_here
TARGET_CALORIES=2000
BED_TIME=22:00

📖 Usage

Processing Food Logs

  1. Export your Telegram chat as JSON (or use the built-in Telegram sync)
  2. Place the export at data/result.json
  3. Run the parser:
uv run python main.py

The tool will:

  • Back up existing data with timestamps
  • Sync latest messages from Telegram
  • Parse food log messages using the LLM
  • Extract ingredients and calculate calories using the food database
  • Generate a calorie trend visualization at data/plot.png

Multi-User Profiles

# List available profiles
uv run python main.py --list-profiles

# Process with a specific profile
uv run python main.py --profile cristina

# Quick daily status for a profile
uv run python main.py --profile cristina --today

Profiles are YAML files in profiles/:

name: "Cristina"
sender_name: "Cristina"
data_path: "/path/to/data"
target_calories: 2000

Telegram Bot

Get daily calorie progress reports via Telegram.

Setup:

  1. Create a bot via @BotFather and copy the token
  2. Get your chat ID from @userinfobot
  3. Add to .env:
    TELEGRAM_BOT_TOKEN=your_bot_token
    TELEGRAM_CHAT_ID=your_chat_id
    

Usage:

# Interactive bot mode
uv run python telegram_bot.py --bot

# One-time report (for cron jobs)
uv run python telegram_bot.py

Commands: /start, /report

Adding Foods to Database

From product label images:

# Place images in labels/ directory (productname_1.jpg, etc.)
uv run python process_labels.py

From supermarket URLs:

# Dry-run (display only)
uv run python scrape_food.py URL

# Add to database
uv run python scrape_food.py --add URL

# With custom name
uv run python scrape_food.py --add --name "food name" URL

Supported sites: Continente.pt

Validation

# Validate all processed data
uv run python main.py validate data/date_messages_map.json

# Inspect specific date
uv run python main.py validate data/date_messages_map.json 2024-03-27

# Quick calorie recalculation check (no LLM)
uv run python scripts/compare_migration.py --quick -n 50

📁 Data Files

File Description
data/result.json Telegram export (input)
data/date_messages_map.json Processed food log data
data/plot.png Calorie trend visualization
food_database.json Nutrition database
data/backups/ Timestamped backups

📚 Documentation

  • CLAUDE.md — Comprehensive architecture guide, data structures, and development workflows
  • docs/pipeline.md — Detailed data processing pipeline documentation

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

parsefood-0.1.0.tar.gz (457.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

parsefood-0.1.0-py3-none-any.whl (487.9 kB view details)

Uploaded Python 3

File details

Details for the file parsefood-0.1.0.tar.gz.

File metadata

  • Download URL: parsefood-0.1.0.tar.gz
  • Upload date:
  • Size: 457.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for parsefood-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f4785d1597c4773036abfdef57b07ec1569444c706e86acf49ebda508d1d08a4
MD5 a217d79ac819d4916c8c470a63682fb7
BLAKE2b-256 ce93764db70e1e34a5137dda75bd58fe2769a779b485cf394548c6a0b948d52b

See more details on using hashes here.

Provenance

The following attestation bundles were made for parsefood-0.1.0.tar.gz:

Publisher: release.yml on tsilva/parsefood

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file parsefood-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: parsefood-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 487.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for parsefood-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dda75e1f2956d3313630ff5816b40714a661c48eda29d0c58fa25dad361e4fb9
MD5 dcc0b83470313bd349a439862ae9ec57
BLAKE2b-256 e01158a424b15916634ba1b11fd5e05c51ace8fff6778f7e9b077e84b8f50001

See more details on using hashes here.

Provenance

The following attestation bundles were made for parsefood-0.1.0-py3-none-any.whl:

Publisher: release.yml on tsilva/parsefood

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page