signal-bot/tool/e2e_logs.py
Krzysztof kuhy Rudnicki 77795ee6f8
Some checks are pending
CI / check (push) Waiting to run
CI / web (push) Waiting to run
Today's food and workout logs, read from where diet_guard and screen_locker keep them
Two commands, food_today and workout_today, each printing the current
Warsaw day out of a log another program owns: every meal with its time,
calories and source plus the day's total and macros; every workout with
every field it carries. Three workout fields are withheld (a reservation
phone number, a screenshot path, the sync record id), and the food budget
is never printed -- diet_guard keeps that number on the machine on purpose.

The spellings the group uses carry a surname, so they are custom aliases in
the state directory; aliases.json ships only plain words. The suite points
both logs at absent temp files so it can never read the operator's own,
and the e2e run writes one invented entry of each under today's date.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-04 22:07:46 +02:00

69 lines
2.1 KiB
Python
Executable File

#!/usr/bin/env python3
# Copyright (c) 2026 Krzysztof Rudnicki. MIT licence.
"""Write a day of invented food and workout logs for the offline end-to-end run.
The real logs are the operator's day, kept by diet_guard and screen_locker
outside this repository; the e2e run must not read them, and could not
count on what they hold. This writes one entry of each under today's
Warsaw date -- the day the bot will ask for -- so the two scenarios have
a known word to look for.
python tool/e2e_logs.py --dir /tmp/logs
"""
from __future__ import annotations
import argparse
import json
import sys
from pathlib import Path
from typing import Final
from signal_bot.stats.periods import today
FOOD_FILE: Final = "food_log.json"
WORKOUT_FILE: Final = "workout_log.json"
MEAL_TIME: Final = "T12:15:00+02:00"
WORKOUT_TIME: Final = "T07:31:13+00:00"
MEAL: Final[dict[str, object]] = {
"desc": "carbonara",
"grams": 350,
"kcal": 550,
"protein_g": 22,
"carbs_g": 60,
"fat_g": 24,
"source": "manual",
}
WORKOUT: Final[dict[str, object]] = {
"workout_data": {
"type": "pc_workout_verified",
"source": "StrongLifts workout B (113 min, all succeeded)",
"duration_minutes": "112.7",
},
}
def write(directory: Path) -> None:
"""Both logs, one entry each, dated today."""
day = today()
directory.mkdir(parents=True, exist_ok=True)
food = {day: [{**MEAL, "time": day + MEAL_TIME}]}
workout = {day: [{**WORKOUT, "timestamp": day + WORKOUT_TIME}]}
(directory / FOOD_FILE).write_text(json.dumps(food, indent=2), encoding="utf-8")
(directory / WORKOUT_FILE).write_text(json.dumps(workout, indent=2), encoding="utf-8")
def main() -> int:
"""Write the logs asked for on the command line."""
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--dir", required=True, type=Path, help="where to write the logs")
arguments = parser.parse_args()
write(arguments.dir)
sys.stdout.write(f"== wrote synthetic food and workout logs to {arguments.dir}\n")
return 0
if __name__ == "__main__":
raise SystemExit(main())