A customizable template for creating AI-powered social media bots using LlamaIndex, Bluesky, and Ollama with RAG functionality.
- ollamaBlueSky.py: Contains core bot logic with RAG setup, file directory reading, and persistent storage.
- BlueSkyBot.py: Handles original API interactions, task scheduling, and posting features.
This project demonstrates my ability to build robust Python applications that interact with APIs, process data, and automate tasks. The BlueSky Social Python Bot automates the posting of text and image content to the BlueSky Social platform using the Atproto client, complete with logging and scheduling capabilities.
- Text Posting: Fetch and post textual data from a specified API endpoint.
- Image Posting: Fetch and post images with metadata such as descriptions and alternative text for accessibility.
- Task Scheduling: Automate tasks to run at periodic intervals using the
schedulelibrary. - Error Handling: Comprehensive logging and error handling for robust performance.
- Secure Configuration: Credentials and API URLs are handled securely using environment variables.
- Ollama RAG Integration: Implements retrieval augmented generation using LlamaIndex with dynamic prompt creation, file directory reading, and persistent storage.
- Python: Core programming language.
atproto: For interacting with the BlueSky Social API.requests: To handle HTTP requests and fetch data.schedule: For periodic task scheduling.logging: For activity and error tracking.tempfile: For efficient temporary file management.
This project highlights my proficiency in:
- API integration and interaction using Python.
- Scheduling and automating tasks.
- Writing maintainable and reusable code.
- Error handling and robust application design.
- Secure handling of sensitive information (e.g., API credentials).
- Python 3.8 or later installed on your machine.
- Basic knowledge of Python and command-line tools.
- APIs to fetch text and images (set up your own or use public ones).
-
Clone the Repository:
git clone https://github.com/MeanFishy00/BlueSky-Social-Python-Bot.git cd BlueSky-Social-Python-Bot -
Install Dependencies:
pip install -r requirements.txt
-
Set Up Environment Variables: Configure your credentials and API endpoints:
export API_USERNAME="your_username" export API_PASSWORD="your_password" export TEXT_API_URL="https://example.com/api/text" export IMAGE_API_URL="https://example.com/api/image"
Alternatively, you can use a
.envfile or a configuration manager likepython-decouple. -
Run the Script:
python script_name.py
- Text Posting:
- Fetches data from the
TEXT_API_URLendpoint. - Posts the
textfield from the API response.
- Fetches data from the
- Image Posting:
- Fetches image content from the
IMAGE_API_URLendpoint. - Saves the image locally using
tempfile. - Posts the image with metadata (description and alt text).
- Fetches image content from the
- Task Scheduler:
- Runs
textPostevery 1 minute andimagePostevery 2 hours by default. - Continuously checks for pending tasks and executes them.
- Runs
.
├── script_name.py # Main script
├── requirements.txt # List of dependencies
└── README.md # Project documentation
textPost: Handles text posting tasks.imagePost: Handles image posting tasks.fetch_data: Fetches JSON data from a given API endpoint.run_scheduler: Configures and runs the task scheduler.
To change the schedule, update the schedule.every calls in run_scheduler:
schedule.every(5).minutes.do(textPost) # Run textPost every 5 minutes
schedule.every(1).hours.do(imagePost) # Run imagePost every 1 hourExtend the script to include:
- Posting other types of media or data.
- Advanced retry mechanisms using libraries like
tenacity.
For testing, consider using pytest or unittest:
- Mock the API responses using
responsesorunittest.mock. - Verify error handling and logging.
- Validate the scheduling functionality.
This project showcases my ability to:
- Build end-to-end Python applications that integrate with APIs.
- Automate and schedule tasks effectively.
- Write secure, maintainable, and production-ready code.
- Solve real-world problems with Python.
This project is licensed under the MIT License. See the LICENSE file for details.
Feel free to connect with me for questions or collaboration:
- GitHub: MeanFishy00
- Email: Isaiah.greenwood01@gmail.com
- LinkedIn: Isaiahgwood
- Portfolio: Repositories