Nutrition Tracker

Analyze in Claude, log here

⚙️ Setup

Calories
0
Goal: 2000
Protein
0g
Goal: 130g
Carbs
0g
Fats
0g

Add Food

Processing...

Today's Food

📋 Setup Instructions

  1. Go to script.google.com → Create new project
  2. Copy the code below and paste it
  3. Click DeployNew Deployment
  4. Type: Web app | Execute as: You | Access: Anyone
  5. Copy the deployment URL and paste in "Apps Script URL" above
function doPost(e) {
  const sheet = SpreadsheetApp.getActiveSheet();
  const data = JSON.parse(e.postData.contents);
  
  sheet.appendRow([
    new Date().toLocaleString(),
    data.foodName,
    data.calories,
    data.protein,
    data.carbs,
    data.fats
  ]);
  
  return ContentService.createTextOutput(JSON.stringify({success: true}));
}

function doGet(e) {
  const sheet = SpreadsheetApp.getActiveSheet();
  const data = sheet.getDataRange().getValues();
  
  const today = new Date().toLocaleDateString();
  const entries = [];
  let totals = {calories: 0, protein: 0, carbs: 0, fats: 0};
  
  for (let i = 1; i < data.length; i++) {
    const date = new Date(data[i][0]).toLocaleDateString();
    if (date === today) {
      entries.push({
        time: data[i][0],
        foodName: data[i][1],
        calories: data[i][2],
        protein: data[i][3],
        carbs: data[i][4],
        fats: data[i][5]
      });
      totals.calories += data[i][2] || 0;
      totals.protein += data[i][3] || 0;
      totals.carbs += data[i][4] || 0;
      totals.fats += data[i][5] || 0;
    }
  }
  
  return ContentService.createTextOutput(JSON.stringify({entries: entries, totals: totals}));
}