feat(food-tracking): add --aliases support to food_items.py and update skill docs
This commit is contained in:
parent
a91cfcd26b
commit
d916c6925b
2 changed files with 21 additions and 1 deletions
|
|
@ -22,6 +22,14 @@ uv run --with pymongo "$SCRIPT" add \
|
|||
--description "Whole milk kefir with old-fashioned rolled oats" \
|
||||
--nutrition '{"calories": 228, "protein_g": 12.1, "fat_g": 7.0, "carbs_g": 30.1, "fiber_g": 3.5, "sugar_g": 6.3}'
|
||||
|
||||
# Add with aliases (for flexible name matching)
|
||||
uv run --with pymongo "$SCRIPT" add \
|
||||
--name "Dave's Killer Bread 21 Whole Grains" \
|
||||
--type food \
|
||||
--serving "1 slice (45g)" \
|
||||
--aliases "large bread,large toast" \
|
||||
--nutrition '{"calories": 110, "protein_g": 6, "fat_g": 1.5, "carbs_g": 22}'
|
||||
|
||||
# Add a medicine
|
||||
uv run --with pymongo "$SCRIPT" add \
|
||||
--name "Excedrin Migraine" \
|
||||
|
|
@ -51,6 +59,9 @@ uv run --with pymongo "$SCRIPT" update --name "Kefir Oats" --set-serving "2 cups
|
|||
# Update an item by _id
|
||||
uv run --with pymongo "$SCRIPT" update --id "6a11b0c3..." --set-nutrition '{"calories": 300, "protein_g": 15, "fat_g": 9, "carbs_g": 40}'
|
||||
|
||||
# Update aliases
|
||||
uv run --with pymongo "$SCRIPT" update --name "Kefir Oats" --set-aliases "kefir oats,ko"
|
||||
|
||||
# Unset a field
|
||||
uv run --with pymongo "$SCRIPT" update --name "Excedrin Migraine" --unset max_dosage
|
||||
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@ def cmd_add(args):
|
|||
except json.JSONDecodeError:
|
||||
print(f"Error: --nutrition must be valid JSON. Got: {args.nutrition}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
if args.aliases:
|
||||
doc["aliases"] = [a.strip() for a in args.aliases.split(",") if a.strip()]
|
||||
if args.extra:
|
||||
try:
|
||||
extra = json.loads(args.extra)
|
||||
|
|
@ -49,7 +51,10 @@ def cmd_get(args):
|
|||
coll, client = get_collection()
|
||||
query = {}
|
||||
if args.name:
|
||||
query["name"] = {"$regex": args.name, "$options": "i"}
|
||||
query["$or"] = [
|
||||
{"name": {"$regex": args.name, "$options": "i"}},
|
||||
{"aliases": {"$regex": args.name, "$options": "i"}},
|
||||
]
|
||||
if args.type:
|
||||
query["type"] = {"$regex": args.type, "$options": "i"}
|
||||
|
||||
|
|
@ -90,6 +95,8 @@ def cmd_update(args):
|
|||
update_fields["description"] = args.set_description
|
||||
if args.set_max_dosage:
|
||||
update_fields["max_dosage"] = args.set_max_dosage
|
||||
if args.set_aliases:
|
||||
update_fields["aliases"] = [a.strip() for a in args.set_aliases.split(",") if a.strip()]
|
||||
if args.set_nutrition:
|
||||
try:
|
||||
update_fields["nutrition"] = json.loads(args.set_nutrition)
|
||||
|
|
@ -142,6 +149,7 @@ def main():
|
|||
p_add.add_argument("--serving")
|
||||
p_add.add_argument("--description")
|
||||
p_add.add_argument("--max-dosage")
|
||||
p_add.add_argument("--aliases", help="Comma-separated alias names, e.g. \"large bread,large toast\"")
|
||||
p_add.add_argument("--nutrition", help='JSON string, e.g. \'{"calories": 228, "protein_g": 12}\'')
|
||||
p_add.add_argument("--extra", help="JSON string with additional fields to merge into the document")
|
||||
|
||||
|
|
@ -160,6 +168,7 @@ def main():
|
|||
p_upd.add_argument("--set-serving", dest="set_serving")
|
||||
p_upd.add_argument("--set-description", dest="set_description")
|
||||
p_upd.add_argument("--set-max-dosage", dest="set_max_dosage")
|
||||
p_upd.add_argument("--set-aliases", dest="set_aliases", help="Comma-separated alias names (replaces existing)")
|
||||
p_upd.add_argument("--set-nutrition", dest="set_nutrition", help="JSON string to replace nutrition")
|
||||
p_upd.add_argument("--set-extra", dest="set_extra", help="JSON string with additional fields to set")
|
||||
p_upd.add_argument("--unset", nargs="*", help="Field names to remove")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue