Mela to Markdown (Python script)
I adore Mela as my recipe manager and meal planner. We use it every single day.
For safekeeping my recipes, I wrote a python script that converts Mela their export to Markdown.
- Export Mela recipes under
Settings > General
. (Only iOS / iPadOS) - Transfer the .melarecipes file to your computer.
- Rename .melarecipes to .zip.
- Extract to preferred folder. There should be a list of
.melarecipe
files. - Add the following Python script to the directory. In the script, under "Define your directories", define where you'd like to store the Markdown recipe and the respective image. (NOTE: the relative path to the image will be parsed in the Markdown.)
- Run the Python script.
import json
import os
import base64
from datetime import datetime
# Define your directories
json_dir = './Recipes' # Correct path to your JSON files
markdown_dir = './Markdown' # Output directory for Markdown files
images_dir = './Attachments/recipeImages' # Directory to store images
# Ensure the Markdown and images directories exist
os.makedirs(markdown_dir, exist_ok=True)
os.makedirs(images_dir, exist_ok=True)
print(f"Markdown directory is set at {markdown_dir}")
print(f"Images will be stored in {images_dir}")
def save_image(title, base64_string):
"""Decode base64 image and save as a JPG file."""
img_data = base64.b64decode(base64_string)
img_filename = f"{title}.jpg".replace(" ", "_")
img_path = os.path.join(images_dir, img_filename)
with open(img_path, 'wb') as img_file:
img_file.write(img_data)
return img_path
def convert_recipe_to_markdown(json_file):
print(f"Processing file: {json_file}")
try:
with open(json_file, 'r', encoding='utf-8') as file:
recipe = json.load(file)
except Exception as e:
print(f"Error reading file {json_file}: {e}")
return
# Frontmatter
markdown_content = "---\n"
markdown_content += "category: recipeNotes\n"
markdown_content += f"title: {recipe['title']}\n"
markdown_content += f"created: {datetime.now().strftime('%Y-%m-%d')}\n" # Assuming creation date is now
markdown_content += f"updated: {datetime.now().strftime('%Y-%m-%d')}\n" # Assuming last updated is now
markdown_content += "---\n\n"
markdown_content += f"# {recipe['title']}\n\n{recipe.get('text', 'No description available.')}\n\n"
if recipe.get('images'):
image_path = save_image(recipe['title'], recipe['images'][0])
markdown_content += f"![{recipe['title']}]({image_path})\n\n"
if 'ingredients' in recipe:
markdown_content += "---\n\n- " + recipe['ingredients'].replace('\n', '\n- ') + "\n\n"
else:
markdown_content += "---\n\nNo ingredients listed.\n\n"
instructions = recipe.get('instructions', 'No instructions provided.')
steps = instructions.split('\n')
formatted_steps = [f"- {step}" for step in steps if step.strip()]
formatted_instructions = '\n'.join(formatted_steps)
markdown_content += "---\n\n" + formatted_instructions + "\n"
# markdown_content += "---\n\n" + recipe.get('instructions', 'No instructions provided.') + "\n"
markdown_filename = os.path.join(markdown_dir, f"{recipe['title']}.md")
try:
with open(markdown_filename, 'w', encoding='utf-8') as md_file:
md_file.write(markdown_content)
print(f"Successfully wrote {markdown_filename}")
except Exception as e:
print(f"Error writing to file {markdown_filename}: {e}")
# Check if the JSON directory exists
if not os.path.exists(json_dir):
print(f"JSON directory {json_dir} does not exist. Please check the path.")
else:
# Loop through all files in the JSON directory
files_processed = 0
for filename in os.listdir(json_dir):
if filename.endswith('.melarecipe'):
convert_recipe_to_markdown(os.path.join(json_dir, filename))
files_processed += 1
if files_processed == 0:
print("No .melarecipe files found in the directory.")
else:
print(f"All recipes processed. {files_processed} files converted.")
← anonymous kudos for permalink
- Exporting Tasks from Things 3 Database to Plain Text technology
- Prevent Browser from Hijacking the Media Keys technology
- LinearMouse–the remedy to Logitech their dumb choices technology
- Today's Lack of Music with an Inherent Value musicology
- External files in Obsidian without duplicating obsidian
- How we value music as an art form musicology
- Controlling Boox Network Traffic technology
- Lay out all Obsidian notes in a grid obsidian
- Highlight callouts in Obsidian obsidian
- AI-assisted music is not the problem musicology
- Display Airplay Now-Playing on old Android Tablet with MQTT smarthome
- Understanding Streaming Music Royalty Payments technology
- My Rating System and Review Criteria musicology
- Display recent files in Obsidian Vault obsidian
- Convert Spotify Library to Markdown scripts
- Things3 Overview in Obsidian obsidian
- List unlinked notes in Obsidian obsidian
- My Zotero research paper template obsidian