Skip to content

monkishtypist/so-many-smoothies.python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Smoothie Recipe Generator

A Python script that uses OpenAI's API to generate unique smoothie recipes with detailed prompts and uploads them to a Sanity CMS. This application also generates unique slugs for each smoothie recipe and associates visually appealing images generated by OpenAI's DALL-E model.

Features

  • AI-Powered Recipe Generation: Generates unique and SEO-friendly smoothie recipes using OpenAI's GPT-4.
  • Image Generation: Creates enticing images for each recipe using OpenAI's DALL-E model.
  • Sanity CMS Integration: Uploads recipes, images, and metadata to a Sanity CMS project.
  • Slug Management: Ensures unique, URL-safe slugs for each smoothie recipe.
  • Daily or Random Prompts: Generates recipes based on predefined daily themes or random prompts.
  • Error Handling: Logs and manages errors during the API interactions or uploads.

Installation

  1. Clone this repository:
    git clone https://github.com/yourusername/smoothie-recipe-generator.git
    cd smoothie-recipe-generator
  2. Install dependencies:
    pip install -r requirements.txt
  3. Set up environment variables:
    • Create a .env file in the root directory with the following variables:
    SANITY_PROJECT_ID=your_sanity_project_id
    SANITY_DATASET=production
    SANITY_WRITE_TOKEN=your_sanity_write_token
    OPENAI_API_KEY=your_openai_api_key

Usage

Generate and Upload a Recipe

Run the script to generate a smoothie recipe based on the daily prompt:

python generate_smoothie.py

Use a Random Prompt

python generate_smoothie.py --random

Dry Run (Test without Uploading to Sanity)

python generate_smoothie.py --dry-run

Slug Generation

The script automatically generates a unique, URL-safe slug for each recipe title. If a conflict is detected (e.g., duplicate titles), a random identifier (using the uuid library) is appended to the slug to ensure uniqueness.

Example:

  • Title: Triple Berry Bliss Smoothie: A Radiant Mix of Nutritious Berries
  • Slug: triple-berry-bliss-smoothie-a-radiant-mix-of-nutritious-berries

File Structure

  • generate_smoothie.py: Main script to generate, parse, and upload recipes.
  • schemaTypes/blockContent.ts: Sanity schema for block content (used in blog posts and descriptions).
  • .env: Environment variables (not included in the repository).
  • requirements.txt: List of dependencies for the script.

Requirements

  • Python 3.7 or higher
  • OpenAI API access
  • Sanity CMS project

Logging

Logs are output to the console with detailed information about each step:

  • Fetching recipe data from OpenAI
  • Generating unique slugs
  • Uploading recipes and images to Sanity CMS
  • Error messages (if any)

Troubleshooting

Common Errors

  1. Missing Environment Variables: Ensure all required variables are set in your .env file.
  2. OpenAI API Errors: Verify your OpenAI API key and check your usage limits.
  3. Sanity Upload Issues: Ensure your Sanity project ID, dataset, and write token are correct.

Contributing

Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.

License

This project is licensed under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages