Instagram Auto-Post Python Bot Creator (Production-Ready)
Generate a complete, fully-functional Python automation script that creates captions via AI and automatically publishes posts to your Instagram using the Meta API. Includes error handling, scheduling, and .env security.
🚀 Instagram Auto-Post Python Bot Architect
Act as an expert Python Automation Engineer and Senior Software Architect. Your task is to generate a complete, production-ready, and highly robust Python script that automates the creation and publishing of Instagram posts using the official Meta Graph API (or a reliable web automation framework like Playwright if explicitly requested, but prioritize the API for stability).
📥 USER INPUTS / PARAMETERS
[Placeholders for the user to fill out before running]
-
Niche/Topic: {TOPIC_OR_NICHE}
-
Content Source: {AI_GENERATED_OR_LOCAL_FOLDER} (e.g., OpenAI GPT-4 for text + DALL-E/Midjourney for images OR pulling from a local assets folder)
-
Posting Schedule: {POSTING_INTERVAL_IN_HOURS} (e.g., Every 12 hours)
-
Caption Style: {CAPTION_STYLE} (e.g., Engaging, educational, emoji-rich, professional)
-
Target Hashtags: {HASHTAGS_LIST}
📋 CORE REQUIRMENTS & ARCHITECTURE
The script must be clean, modular, well-commented, and include the following architectural components:
- Environment & Credential Management:
-
Use .env file for sensitive keys INSTAGRAM_BUSINESS_ACCOUNT_ID, FACEBOOK_PAGE_ACCESS_TOKEN, OPENAI_API_KEY, etc.).
-
Include a template for the .env file in the comments.
- Content Generation/Retrieval Module:
-
If AI-generated: Integrate openai Python SDK to generate a highly engaging caption based on the {CAPTION_STYLE} and automatically generate/download a relevant image.
-
If Local: Scan a specified ./assets/ folder, pick the next available image, and pair it with a pre-written text file or generate a caption based on the image name.
- Instagram API Integration:
- Implement the Meta Graph API container system:
Step A: Upload image to a public URL (or use a temporary hosting workaround if running locally).
Step B: Create a media item container via POST request to /v17.0/{account_id}/media.
Step C: Publish the container via POST request to /v17.0/{account_id}/media_publish.
- Error Handling & Logging:
-
Implement robust standard logging logging module) to log success messages, API errors, and network timeouts to both the console and an automation.log file.
-
Include retry logic (exponential backoff) for failed API requests.
- Scheduler:
- Use the schedule or apscheduler library to run the script indefinitely based on the {POSTING_INTERVAL_IN_HOURS}.
🛠️ OUTPUT FORMAT
Your response must include:
-
Prerequisites: Clear pip install commands for all required libraries.
-
Configuration: The .env file structure.
-
The Python Script: A single, fully-functional, beautifully formatted .py file containing all the logic. Do not use placeholders inside the code logic; use variables that read from the environment or user input.
-
Instructions: Short instructions on how to obtain Meta API tokens and run the script safely without getting banned.
Let's build the ultimate Instagram automation tool!
Related Prompts
More prompts in Coding & Development
This Prompt Ads Sequential Function Calling To Models Other Than GPT 0613
This prompt ads sequential function calling to models other than GPT-0613
Create a personalized workout routine
Tailor a workout routine specifically designed for individual fitness goals
GODMODE CHEATCODE
God Writes You a Letter Today. This is will help you find the perfect Bible Scripture that will guide you through a current problem you're facing.
Creating a Personal Finance Tracker with [Technology/Tool]
Learn to create a personal finance tracker using [Technology/Tool]. Get code samples and budgeting tips.
Build an entire application using bubble.io with ChatGPT4
Build an entire app with bubble.io, assisted by chatGPT4, that knows bubble very well and is accurate 95% of the time. This prompt will help you maximize the quality of chatGPT assistance. Having detailed and step-by-step instructions is essential to progress fast with Bubble. This initial prompt will help you get started on a good basis. Follow it because I will make it even better.
Become LawyerGPT
Are you in a legal bind? This prompt can help you gain knowledge about how to handle your legal proceedings. DISCLAIMER: Please meet with a real lawyer to discuss your options.