notion_weekly_report
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Viewing readonly version of main branch: v401View latest version
This walkthrough summarizes how the Notion Life Tracker was built, in the order the pieces were added and refined.
- Created two databases: Blood Sugar Log and Food Log.
- Blood sugar properties:
Entry(Title),Created time(Created time),Blood Sugar Level(Number). - Food properties:
food(Title/Text),Created time(Created time), plus macro fields likecalories,protein,carbs,fats,fiber,sugar,sodium.
- Created a Notion integration, shared it with both databases.
- Stored secrets for Val Town:
NOTION_TOKENNOTION_BLOOD_SUGAR_DB_IDNOTION_FOOD_DB_ID
- Implemented
shared/notion.tsto query pages and update page properties. - Added minimal Notion types and error handling for invalid responses.
- Implemented
shared/date.tsfor weekly ranges, date lists, and streak counts. - Centralized UTC date logic for consistent weekly rollups.
- Implemented
shared/blood_sugar_logic.ts:- Parse Notion pages into normalized entries.
- Group by date and compute weekly stats (avg/min/max, completion rate, streaks).
- Render email-friendly summaries.
- Added XP and badge logic for motivational feedback.
- Implemented
collectors/blood_sugar_report.cron.tsx:- Query the last 7 days from Notion.
- Build a summary report and send it via Val Town email.
- Persist weekly rollups to SQLite.
- Added timezone-aware date extraction for blood sugar entries (America/New_York).
- Prevented late-night readings from rolling into the next UTC day.
- Implemented
shared/food_enrich.ts:- Parse food entries and read existing macros from Notion.
- Only enrich entries missing core macros.
- Build update payloads for Notion.
- Compute weekly food rollups and macro summaries.
- Implemented
shared/fatsecret.ts:- OAuth token retrieval.
- Food search and macro parsing from FatSecret responses.
- Implemented
collectors/food_report.cron.tsx:- Fetch weekly food entries.
- Normalize food names with OpenAI.
- Fetch nutrition data and write macros back to Notion.
- Persist weekly rollups to SQLite.
- Added fiber, sugar, and sodium parsing from FatSecret.
- Summed those fields across multi-item meals when all items provide values.
- Added a
food.getcall to pull detailed nutrition data when available. - Kept
food_descriptionparsing as a fallback.
- Updated OpenAI normalization to emit
{ name, servings }per item. - Scaled FatSecret macros by the inferred servings.
- Defaulted to one serving for typical meals (e.g., "shrimp lo mein").
- Fixed TypeScript inference edge cases and unused params.
- Verified
deno lintpasses across the codebase.
- Clarified required Notion fields.
- Documented the OpenAI normalization + FatSecret detail workflow.
- Added serving size examples for clarity.
If you want, I can expand this into a full contributor guide with diagrams or link each step to the exact files and functions.
