add delete food item in skill
This commit is contained in:
parent
87a5ca6555
commit
a91cfcd26b
2 changed files with 20 additions and 1 deletions
|
|
@ -89,6 +89,9 @@ uv run --with pymongo "$SCRIPT" update --id "6a11a937..." --set-amount 2 --set-u
|
||||||
|
|
||||||
# Unset a field
|
# Unset a field
|
||||||
uv run --with pymongo "$SCRIPT" update --id "6a11a937..." --unset unit
|
uv run --with pymongo "$SCRIPT" update --id "6a11a937..." --unset unit
|
||||||
|
|
||||||
|
# Delete an entry
|
||||||
|
uv run --with pymongo "$SCRIPT" delete --id "6a11a937..."
|
||||||
```
|
```
|
||||||
|
|
||||||
## Workflow Notes
|
## Workflow Notes
|
||||||
|
|
|
||||||
|
|
@ -125,6 +125,18 @@ def cmd_update(args):
|
||||||
print("No matching entry found.")
|
print("No matching entry found.")
|
||||||
client.close()
|
client.close()
|
||||||
|
|
||||||
|
def cmd_delete(args):
|
||||||
|
from bson import ObjectId
|
||||||
|
coll, client = get_collection()
|
||||||
|
|
||||||
|
if not args.id:
|
||||||
|
print("Error: --id is required for delete", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
result = coll.delete_one({"_id": ObjectId(args.id)})
|
||||||
|
print(f"Deleted: {result.deleted_count}")
|
||||||
|
client.close()
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(description="Manage food log entries in lists.food_log")
|
parser = argparse.ArgumentParser(description="Manage food log entries in lists.food_log")
|
||||||
sub = parser.add_subparsers(dest="command", required=True)
|
sub = parser.add_subparsers(dest="command", required=True)
|
||||||
|
|
@ -155,8 +167,12 @@ def main():
|
||||||
p_upd.add_argument("--set-extra", dest="set_extra", help="JSON string with additional fields to set")
|
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")
|
p_upd.add_argument("--unset", nargs="*", help="Field names to remove")
|
||||||
|
|
||||||
|
# delete
|
||||||
|
p_del = sub.add_parser("delete", help="Delete a food log entry")
|
||||||
|
p_del.add_argument("--id", required=True, help="ObjectId to delete")
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
{"add": cmd_add, "get": cmd_get, "update": cmd_update}[args.command](args)
|
{"add": cmd_add, "get": cmd_get, "update": cmd_update, "delete": cmd_delete}[args.command](args)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue