DEV Community

Cover image for Automate your Instagram Posts like a PRO with Cron jobs! πŸš€

Automate your Instagram Posts like a PRO with Cron jobs! πŸš€

Shrijal Acharya on August 10, 2024

TL;DR ✨ In this easy-to-follow tutorial, you will learn how to build your own Instagram Automation tool from scratch with cron jobs. 😎 ...
Collapse
 
larastewart_engdev profile image
Lara Stewart - DevOps Cloud Engineer

Wow, wow, wow β€” I love this article so much! Just following what others do is not how I define a programmer; finding an unusual way to solve real-world problems is where creativity comes in.

Who would've thought that anyone could use something as simple as a cron job to automate posting on social media?

I am definitely spinning this up on my Ubuntu server running in my homelab. Cheers to you. πŸ₯‚

Collapse
 
larastewart_engdev profile image
Lara Stewart - DevOps Cloud Engineer

To be honest, I didn't know you could create an entire image with NumPy arrays. I don't work with Python much but Wow!

Collapse
 
shricodev profile image
Shrijal Acharya

I'm glad I could share it with you. πŸ˜„ Here, we're generating an image using the Pillow library from NumPy arrays, so the image generation isn't solely based on NumPy.

Collapse
 
shricodev profile image
Shrijal Acharya

I'm glad that you liked it. ☺️

Collapse
 
shricodev profile image
Shrijal Acharya

Let me know your thoughts on this πŸ‘€

Collapse
 
neurabot profile image
Neurabot • Edited

Seems to be well-explained article. I think it can be applied to own social media.

Collapse
 
shricodev profile image
Shrijal Acharya

@heyeasley Glad you liked it! 😊

Collapse
 
mukesh_singhania_1992 profile image
Mukesh Singhania

You've written a complete book. 23Β min long article πŸ’€

Collapse
 
shricodev profile image
Shrijal Acharya

Hope you enjoyed reading this.

Collapse
 
mukesh_singhania_1992 profile image
Mukesh Singhania

But, I love the fact that the code is very crisp and well documented. Saving it for later.

Collapse
 
denys_bochko profile image
Denys Bochko

while it is a very good article and I am going to read it in detail shortly, I am going to ask a question about whether it will impact your account.

I was using a Mac app to view my account on my desktop and recently Instagram logged me out saying that I am using automation to view my account, which is apparently against the rules. After that, I got logged off on my mobile so I had to log back again and I could not get into that app anymore.
Just curious of there is a possibility of getting the same behaviour using this cron? Not against the automation, I am all for that, but when you deal with Meta, it's a different story.

Collapse
 
shricodev profile image
Shrijal Acharya

This shouldn't have any security complications, to be honest, as long as Instagram is happy to expose its API (and you ensure that nobody other than you can view your .env file with your username and password). Do keep in mind that the first time you try this from your system, have Instagram open in another tab, as it may ask if the device trying to access your account is indeed yours.

But make sure you don't have a post scheduled for every other minute, as it will try to log in to Instagram for each post.

Collapse
 
bh4skar profile image
Bhaskar Prajapati

This is one big post. Bookmarking it for later. As long as you use it inside a cloud VM, this script will be a lifesaver.

Collapse
 
shricodev profile image
Shrijal Acharya

Exactly. If you plan to use this on your own computer, it should be when your computer is powered on most of the time.

If you have a cloud VM or a home lab setup, this should be a lifesaver.

Collapse
 
shekharrr profile image
Shekhar Rajput

I love the fact that you using docsttring in the documentation!

Collapse
 
shekharrr profile image
Shekhar Rajput

Almost after a week, I still see this 23 min read blog on my feed. Great to see it performing well. πŸ‘πŸ½

Collapse
 
shricodev profile image
Shrijal Acharya

Thank you πŸ˜€

Collapse
 
basspod profile image
Paul ODell

This is amazing! I love this project. But when I take a step back. What problem is it solving?

Collapse
 
shricodev profile image
Shrijal Acharya

I’m glad you liked it! 😊 It can definitely come in handy if you have a few images that you want to post on Instagram, but not right away β€” just on a certain day.

I can't say this is super useful all the time, but it can come in handy at times. After I wrote this article, I found out that Instagram offers this feature for professional accounts: help.instagram.com/439971288310029.

Not everyone would want to switch their account to professional, though. The idea of Instagram automation came to me when I built a GNOME wallpaper changer script that updates my wallpaper every 3 hours using cron jobs and decided to code it up and share with you all.

Collapse
 
basspod profile image
Paul ODell

Great work around to get the professional account feature!

Collapse
 
aayyusshh_69 profile image
Aayush Pokharel

Wow, good piece. I don't know anything about shell scripting and all.
Definitely not a beginner like me πŸ₯² friendly article . Try changing the experience level.

Collapse
 
shricodev profile image
Shrijal Acharya

I just noticed that the post experience is set to the first stage of the Advanced graph by default.

Collapse
 
shricodev profile image
Shrijal Acharya

I've tried documenting portions of the code itself, so the article won't be over half an hour long.

Collapse
 
martinbaun profile image
Martin Baun

TIL. Interesting!

Collapse
 
shricodev profile image
Shrijal Acharya

Glad you found it helpful! πŸ˜„

Collapse
 
sami_reg_bc7f377019e7cf4c profile image
SAMI REG

I still didn't read that since it's 2:30 a.m now
But I'm willing to go back to that
However I have a question, any idea about how can I make a code to automate replies and DMs based on some triggers on the comments
That's what I was looking for and I came across your article
I've used python more than any other language, but I'm not expert tho, but I'm definitely willing to commit to learn how to automate my Instagram business using my own code, I don't mind if I'll need to use other languages, but I'll be happier if it's python

Please tell me if you know the answer to my request or at least lead me to where did you learn the post automation, I might find my need in your sources πŸ™πŸΎ

Collapse
 
shricodev profile image
Shrijal Acharya

Hey @sami_reg_bc7f377019e7cf4c, sorry for the late response! 😢 I just saw your comment in my notifications.

Regarding handling comments on Instagram posts, I noticed that instagrapi supports a Comment API which you can use to manage comments on your post.

However I have a question, any idea about how can I make a code to automate replies and DMs based on some triggers on the comments

To automate commenting based on triggers in comments using my cron job approach, you can build a similar Python script that tracks the comment state (number of comments) on your post (the Comment API allows you to check the comment count). You can schedule this script to run daily, hourly, or even every minute. If a new comment is detected, you can add a standard reply to those comments.

I hope this makes sense! If you need any extra help, feel free to ask.

Collapse
 
sami_reg_bc7f377019e7cf4c profile image
SAMI REG

Oh thank you, I was busy too so I haven't get back here until now.

You said it's possible to handle comments through 2 ways

But either I missed or you really didn't say anything about DM's right? Are they also possible to automate through the same trigger

Client comment > Detect trigger > auto reply + auto DM

What do you think? And thank you again and sorry for being clingy haha

Thread Thread
 
shricodev profile image
Shrijal Acharya

@sami_reg_bc7f377019e7cf4c Yes, there is support for DMs as well. As I mentioned, for replying to comments, you can also set up DMs. Instagrapi has documentation on DMs here.

Let me know if you need any extra help. πŸ™Œ

Thread Thread
 
sami_reg_bc7f377019e7cf4c profile image
SAMI REG

God bless you πŸ™ŒπŸΎπŸ™ŒπŸΎ