insta-cron-post-automation

SAā€¢View on GitHubā€¢March 23, 2024
cronjob
cronjob-scheduler
instagrapi
linux
python3

Insta Cron Post Automation šŸ ā°

šŸ“š Overview

The Python Insta Post Scheduler is a Python application designed to automate Instagram posts by scheduling them using Cronjobs. This project allows you to post image to Instagram with optional metadata and control various post settings per each post.

šŸ˜Ž Features

  • Automated Posting: Schedule Instagram posts using cron jobs.
  • Flexible Configuration: Define post details and settings in JSON files.
  • Custom Logging: Detailed logging of events and errors.
  • Environment Variable Management: Securely manage Instagram credentials using environment variables.

āš ļø Limitations

Since this script uses cron jobs, it will only be able to run the scheduled posts if the scheduled system is up and running. Therefore, it is recommended to run this script in cloud environments in a VM or any environment of your choice. ā˜ļø

šŸŒ³ Project Structure

insta-cron-post-automation/
ā”œā”€ā”€ .git/
ā”œā”€ā”€ (gitignored) .venv/
ā”œā”€ā”€ data/
ā”‚   ā”œā”€ā”€ generated_images/
ā”‚   ā”‚   ā”œā”€ā”€ .gitkeep
ā”‚   ā”‚   ā”œā”€ā”€ (gitignored) sample_image_0.jpg
ā”‚   ā”‚   ā””ā”€ā”€ ...
ā”‚   ā”œā”€ā”€ scheduled_posts/
ā”‚   ā”‚   ā”œā”€ā”€ .gitkeep
ā”‚   ā”‚   ā”œā”€ā”€ (gitignored) insta_post_1cogp9_2024-07-24-11-42.json
ā”‚   ā”‚   ā””ā”€ā”€ ...
ā”‚   ā”œā”€ā”€ error.json
ā”‚   ā”œā”€ā”€ success.json
ā”‚   ā””ā”€ā”€ to-post.json
ā”œā”€ā”€ logs/
ā”‚   ā”œā”€ā”€ .gitkeep
ā”‚   ā””ā”€ā”€ (gitignored) post-activity.log
ā”‚   ā””ā”€ā”€ (gitignored) shell-error.log
ā”œā”€ā”€ src/
ā”‚   ā”œā”€ā”€ (gitignored) __pycache__/
ā”‚   ā”œā”€ā”€ scripts/
ā”‚   ā”‚   ā”œā”€ā”€ run_media_post.fish
ā”‚   ā”‚   ā””ā”€ā”€ run_media_post.sh
ā”‚   ā”œā”€ā”€ logger_config.py
ā”‚   ā”œā”€ā”€ media_post.py
ā”‚   ā”œā”€ā”€ populate_sample_posts.py
ā”‚   ā”œā”€ā”€ post.py
ā”‚   ā”œā”€ā”€ post_list.py
ā”‚   ā””ā”€ā”€ setup.py
ā”œā”€ā”€ (gitignored) .env
ā”œā”€ā”€ .env.example
ā”œā”€ā”€ .gitignore
ā”œā”€ā”€ main.py
ā”œā”€ā”€ README.md
ā””ā”€ā”€ requirements.json

šŸ› ļø Installation

  • Clone the Repository

šŸ’¬ If you are using HTTPS protocol instead of SSH, change the git clone command accordingly.

git clone git@github.com:shricodev/insta-cron-post-automation.git
cd insta-cron-post-automation
  • Create and Activate Virtual Environment
python3 -m venv .venv
source .venv/bin/activate.fish # or .venv/bin/activate if you are not using the fish shell
  • Install Dependencies
pip3 install -r requirements.json
  • Set Up Environment Variables
INSTA_USERNAME=<your_instagram_username>
INSTA_PASSWORD=<your_instagram_password>

You can use the .env.example file as a template.

šŸ’» Usage

  • Configure Posts

Edit the data/to-post.json file to include the posts you want to schedule. Ensure each post has the required fields:

{
  "image_path": "path/to/image.jpg",
  "description": "Post description",
  # The post date needs to follow this syntax
  "post_date": "2024-07-06 08:08"
  # Optional
  "extra_data": {
    "custom_accessibility_caption": "Accessibility caption",
    "like_and_view_counts_disabled": 0,
    "disable_comments": 0
  },
}
  • Schedule Posts

Run the main.py script to schedule your posts:

python3 main.py

This script will:

  • Load posts from the JSON file.
  • Creates an individual json file for each post inside the data/scheduled_posts/ directory.
  • Schedule cron jobs to post at the specified times.

šŸ’¬ Logging

The application logs detailed information about events and errors. You can view the logs in the logs/post-activity.log and logs/shell-error.log file. Also, you can view the success and error logs for each post in the data/success.json and data/error.json files respectively.

Show your support

Give a ā­ļø if this project helped you!