This app automates the process of creating and updating a blog using AI-generated content and images. It leverages the OpenAI API for generating blog content and images, GitPython for managing the blog repository, and BeautifulSoup for manipulating HTML files.
Before using the script, ensure that you have the following:
- Python 3 installed on your system.
- OpenAI API key: You need to have a valid OpenAI API key to generate blog content and images. Visit the OpenAI website to obtain an API key.
- GitPython: Install the GitPython library by running
pip install GitPython
. - BeautifulSoup: Install the BeautifulSoup library by running
pip install beautifulsoup4
. - Tailwind CSS: The generated HTML files are styled using Tailwind CSS. The required stylesheets are loaded from the CDN, so an internet connection is necessary.
- Clone the AI blog repository:
git clone <repository-url>
- IMPORTANT STEP!!! Set the environment variable:
export OPENAI_API_KEY=<your-api-key>
Replace with your actual OpenAI API key.
In the script, modify the PATH_TO_BLOG_REPO variable to point to the local path of your cloned AI blog repository.
pip install openai requests
The script performs the following steps:
Generate blog content and image using the OpenAI API. Save the image locally. Create a new blog HTML file. Update the index HTML file with the link to the new blog. Commit and push the changes to the Git repository. To use the script, simply run it:
python main.py
Make sure you are in the same directory as the main.py file.
As shown above, the generated HTML files have a simple design as the main point of this project was getting the backend to work. Each card contains the blog title, cover image, and content.
Contributions are welcome! If you find any issues or have suggestions for improvement, feel free to open an issue or submit a pull request.
This project is licensed under the MIT License.
This README provides a comprehensive guide to the AI blog script, including prerequisites, setup instructions, usage details, generated HTML style, contribution guidelines, and license information. The code snippets and image are preserved, and line-by-line explanations are added within the code blocks.
Jon Christie