Skip to content

Instantly share code, notes, and snippets.

@wsargent
Created March 1, 2025 21:28
Adds a note to recipe in mealie.
import re
import requests
import os
import json
def add_recipe_note(recipe_slug: str, note_title: str, note_text:str) -> None:
"""
Appends a new note to the given recipe in Mealie.
Parameters
----------
recipe_slug : str
The slug of the recipe to update.
note_title : str
The title of the node (relevant to discussion)
note_text: str
The text of the note (chef recommendation and summary, may be used for archival memory purposes)
Returns
-------
None
"""
endpoint = os.getenv("MEALIE_ENDPOINT")
api_key = os.getenv("MEALIE_API_KEY")
headers = {
"accept": "application/json",
"Authorization": "Bearer " + api_key
}
def snake_case(text):
# Replace spaces and other separators with underscores and convert to lowercase
return re.sub(r'[^a-zA-Z0-9]+', '_', text).lower()
def printd(data):
print(json.dumps(data, indent=4, sort_keys=True))
def get_recipe_notes(recipe_slug: str) -> list:
"""
Gets the notes for a recipe.
Parameters
----------
recipe_slug : str
The slug of the recipe to get the notes for.
Returns
-------
list
The list of notes for the recipe.
"""
recipe_response = requests.get(
f"{endpoint}/api/recipes/{recipe_slug}",
headers = headers
)
recipe_response.raise_for_status()
recipe = recipe_response.json()
return recipe["notes"]
def add_note_to_recipe(slug: str, note_title: str, note_text: str) -> list:
"""
Adds a note to a recipe.
Parameters
----------
slug : str
The slug of the recipe to add the note to.
note_title : str
The title of the note to add.
note_text : str
The text of the note to add.
Returns
-------
list
The list of notes.
"""
notes = get_recipe_notes(slug)
new_note = {
"title": note_title,
"text": note_text
}
notes.append(new_note)
body = {
"notes": notes
}
response = requests.patch(
f"{endpoint}/api/recipes/{slug}",
json=body,
headers = headers
)
response.raise_for_status()
return response.json()["notes"]
add_note_to_recipe(recipe_slug, note_title = note_title, note_text = note_text)
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment