Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 63 additions & 40 deletions .claude/skills/lookup_nutrition.md
Original file line number Diff line number Diff line change
@@ -1,52 +1,90 @@
# Look Up Nutritional Information

Find accurate nutritional data for foods using the local USDA database.
Find accurate nutritional data for foods using multiple databases.

## Primary Source: Local USDA Database
## Available Data Sources

Use the lookup script to search Foundation Foods:
1. **USDA Foundation Foods** (local) - ~365 whole foods, high accuracy
2. **Open Food Facts** (online) - Millions of packaged products, barcodes, European foods

## Unified Lookup (Recommended)

Search both databases at once:

```bash
python3 scripts/lookup_usda.py "food name"
python3 scripts/lookup_nutrition.py "food name"
```

Options:
- `--limit N` - Return top N matches (default 5)
- `--portions` - Include standard portion sizes
- `--limit N` - Max results per source (default 5)
- `--portions` - Include standard portion sizes (USDA only)
- `--json` - Output as JSON for easier parsing
- `--id FDC_ID` - Look up by specific FDC ID
- `--source usda|off` - Search only one database
- `--country NAME` - Filter Open Food Facts by country (e.g., switzerland, germany)

### Barcode Lookup

### Example
Look up packaged products by barcode (EAN/UPC):

```bash
python3 scripts/lookup_nutrition.py --barcode 3017620422003
```

### USDA ID Lookup

Look up by specific USDA FDC ID:

```bash
python3 scripts/lookup_nutrition.py --id 171705
```

## Individual Scripts

For specific databases only:

```bash
# USDA only (local, offline)
python3 scripts/lookup_usda.py "chicken breast" --portions

# Open Food Facts only (online, European foods, barcodes)
python3 scripts/lookup_openfoodfacts.py "gruyere" --country switzerland
python3 scripts/lookup_openfoodfacts.py --barcode 7613035844674
```

Returns per-100g nutrient values plus portion options.
## Examples

## Fallback Sources (when not in USDA data)
```bash
# Search all databases
python3 scripts/lookup_nutrition.py "eggs" --limit 3

1. **User-provided info** - Nutrition labels, specific values
2. **Brand websites** - For packaged/branded foods
3. **Web search** - Last resort, cite source
# Swiss cheeses and European foods
python3 scripts/lookup_nutrition.py "emmental" --country switzerland

## Process
# Packaged product by barcode
python3 scripts/lookup_nutrition.py --barcode 3017620422003

1. Search local USDA database first
2. If no match or ambiguous, ask for clarification:
- Preparation method (raw, cooked, fried)
- Specific variety
- Brand (for packaged foods)
3. If not in USDA, fall back to other sources
4. Return breakdown with source noted
# Only local USDA data
python3 scripts/lookup_nutrition.py "salmon" --source usda --portions
```

## Scaling to Portion Size

USDA values are per 100g. To scale:
Values are per 100g. To scale:
- Get the amount in grams
- Multiply each nutrient by (amount_g / 100)

The `--portions` flag shows common serving sizes with gram weights.
Use `--portions` to see common serving sizes with gram weights (USDA only).

## Process

1. Search local USDA database first for whole foods
2. Search Open Food Facts for packaged/branded items
3. If user has a barcode, use barcode lookup
4. If no match or ambiguous, ask for clarification:
- Preparation method (raw, cooked, fried)
- Specific variety
- Brand (for packaged foods)
5. Return breakdown with source noted

## What to Return

Expand All @@ -61,26 +99,11 @@ If available:
- Saturated fat, trans fat
- Sodium, potassium
- Vitamins and minerals
- Nutri-Score (Open Food Facts)

## Handling Uncertainty

- If multiple matches, show options: "Did you mean X or Y?"
- If portion unclear, use standard serving from `--portions`
- For home-cooked meals, break into ingredients and sum

## Example Interaction

User: "One chicken breast"

```bash
python3 scripts/lookup_usda.py "chicken breast" --portions --json
```

Response: "A raw chicken breast with skin (FDC ID: 2727569) per 100g:
- Calories: not listed (estimate ~165 kcal)
- Protein: 21.4g
- Fat: 4.78g
- Carbs: ~0g

The USDA shows this without calorie data. A typical breast is ~175g.
Should I log 175g chicken breast?"
- Note the source (USDA vs Open Food Facts) in responses
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
*.egg-info/
dist/
build/

# Environment
.env
.venv/
venv/

# IDE
.idea/
.vscode/
*.swp
*.swo

# OS
.DS_Store
Thumbs.db
116 changes: 85 additions & 31 deletions ISSUES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,65 @@

## Recently Completed ✓

### ~~3. Improve food search/matching~~ ✓ Completed 2026-01-15
### ~~1. Add European/Swiss nutritional database~~ ✓ Completed 2026-01-15

**Labels:** enhancement, data

Integrated Open Food Facts API with country-specific filtering:
- **International coverage** - Millions of products from around the world
- **Swiss/European foods** - Use `--country switzerland` (or germany, france, etc.)
- **Country-specific subdomains** - Routes to regional OFF databases for better results

Files added:
- `scripts/lookup_openfoodfacts.py` - Open Food Facts API integration
- `scripts/lookup_nutrition.py` - Unified lookup across all databases

Example: `python3 scripts/lookup_nutrition.py "gruyere" --country switzerland`

---

### ~~2. Expand food database beyond 365 items~~ ✓ Completed 2026-01-15

**Labels:** enhancement, data

Added Open Food Facts integration providing access to millions of products:
- **No bundling required** - Uses Open Food Facts API (online)
- **Unified search** - Single command searches both USDA and OFF
- **Source tracking** - Results show [USDA] or [OFF] labels

Files added:
- `scripts/lookup_openfoodfacts.py`
- `scripts/lookup_nutrition.py`

Updated: `.claude/skills/lookup_nutrition.md`

---

### ~~3. Add barcode/packaging photo support~~ ✓ Completed 2026-01-15

**Labels:** enhancement, feature

Implemented barcode lookup via Open Food Facts:
- **EAN/UPC support** - Look up any barcode in OFF database
- **Nutri-Score included** - Shows grade when available
- **Brand and quantity** - Displays product details

Usage:
```bash
python3 scripts/lookup_nutrition.py --barcode 3017620422003
# or
python3 scripts/lookup_openfoodfacts.py --barcode 3017620422003
```

Note: Photo/OCR extraction requires vision-capable LLM to read barcode from image first.

Files added:
- `scripts/lookup_openfoodfacts.py`
- `scripts/lookup_nutrition.py`

---

### ~~4. Improve food search/matching~~ ✓ Completed 2026-01-15

**Labels:** enhancement

Expand Down Expand Up @@ -59,55 +117,51 @@ Copy these to GitHub Issues when ready.

---

## 1. Add European/Swiss nutritional database
## 7. Add dedicated Swiss database integration

**Labels:** enhancement, data

### Problem
The current USDA Foundation Foods dataset is US-focused. Missing:
- Swiss cheeses (Gruyère, Emmental, Appenzeller, Raclette)
- European sausages (Cervelat, Bratwurst)
- Regional foods and preparations
While Open Food Facts provides some Swiss products, the official Swiss Food Composition Database (Schweizer Nährwertdatenbank) at https://naehrwertdaten.ch/ has more accurate data for traditional Swiss foods.

### Potential sources
- **Swiss Food Composition Database** (Schweizer Nährwertdatenbank) - https://naehrwertdaten.ch/
- **German BLS** (Bundeslebensmittelschlüssel)
- **Open Food Facts** - crowdsourced, international coverage
- **Swiss Food Composition Database** - Official government data
- **German BLS** (Bundeslebensmittelschlüssel) - Comprehensive German database

### Implementation
- Download and integrate additional database(s)
- Update `lookup_usda.py` to search multiple sources (or create unified `lookup_nutrition.py`)
- Add source field to track where data came from
- Download official Swiss database
- Create `lookup_swiss.py` script
- Integrate into unified `lookup_nutrition.py`

---

## 2. Expand food database beyond 365 items

**Labels:** enhancement, data
## 8. Image recognition for meals

### Problem
USDA Foundation Foods only has 365 foods. Missing many common items.
**Labels:** enhancement, feature

### Options
- **USDA SR Legacy** - ~8,000 foods, older but more comprehensive
- **USDA Branded Foods** - 300k+ items but 3GB (too large to bundle)
- **Open Food Facts** - millions of products, crowdsourced
### Description
Allow users to photograph a meal and have it analyzed:
1. Vision LLM identifies food items in the photo
2. Estimates portions based on visual cues
3. Looks up nutrition and logs the meal

### Consideration
Trade-off between database size and repo size. Could offer download script instead of bundling.
### Dependencies
- Requires multimodal LLM with vision capabilities
- Good portion estimation logic

---

## 3. Add barcode/packaging photo support
## 9. Goal tracking and recommendations

**Labels:** enhancement, feature

### Description
When user photographs food packaging:
1. Extract barcode or product name
2. Look up in Open Food Facts or similar
3. Auto-populate nutritional values
Provide actionable recommendations based on intake patterns:
- Suggest foods to fill nutrient gaps
- Alert when approaching daily limits
- Weekly goal progress tracking

### Dependencies
- Requires vision-capable LLM
- Open Food Facts API or local database
### Implementation
- Analyze weekly_summary data
- Build recommendation engine
- Add notification/alert system
Loading