That’s why I decided to use my Python skills to create a bot that could do that for me. I wanted to make my profile more fun and dynamic by changing my profile picture every x seconds. In this blog post, I will show you how I did it and what challenges I faced along the way.
Step 1: Getting the pictures
The first step was to get the pictures that I wanted to use as my profile pictures. I decided to use some of my favorite memes and gifs that I found online. I downloaded them and saved them in a folder called /data on my computer. Then, I renamed them as “pic1, pic2, pic3, … picX” so that I could easily loop through them later.
Step 2: Getting the ENC Password
The next step was to get my profile’s ENC Password, which is a special password that Instagram requires for login requests after its updates. To get it, I had to use a tool called Instaloader, which is a Python library that allows you to download Instagram posts, stories, highlights, and more. I installed it using pip and ran the following command in the terminal:
instaloader -l username
This prompted me to enter my regular Instagram password and then gave me my ENC Password, which looked something like this:
#pw+Z6tF4I4zQ==\n
I copied it and saved it in a file called enc_password.txt in the same folder as my pictures.
Step 3: Writing the bot
The final step was to write the bot that could change my profile picture every x seconds. For this, I used another Python library called InstaPy, which is a tool that automates Instagram actions such as liking, commenting, following, and more. I installed it using pip and imported it in my script:
from instapy import InstaPy
Then, I created an instance of InstaPy with my username and ENC Password:
session = InstaPy(username="username", enc_password="#pw+Z6tF4I4zQ==\n")
Next, I logged into Instagram using the login() method:
session.login()
After that, I wrote a loop that iterated through the pictures in the /data folder and changed my profile picture using the set_profile_pic() method:
import os
import time
pics = os.listdir("data")
for pic in pics:
session.set_profile_pic("data/" + pic)
time.sleep(x) # x is the number of seconds you want to wait before changing the picture again
Finally, I logged out of Instagram using the end() method:
session.end()
And that’s it! I ran the script and watched as my profile picture changed every x seconds. It was fun to see how my followers reacted to my changing profile.
Challenges and limitations
Of course, this project was not without its challenges and limitations. Here are some of them:
- The ENC Password can expire after some time or after logging out of Instagram on other devices. In that case, you have to get a new one using Instaloader again.
- The set_profile_pic() method can sometimes fail or take longer than expected. This can cause some delays or errors in the loop.
- Instagram can detect unusual activity on your account and block or ban you for violating its terms of service. This can happen if you change your profile picture too frequently or too randomly. To avoid this, you should use a reasonable value for x and not run the bot for too long.
Conclusion
In this blog post, I showed you how I made a bot that could change my Instagram profile picture every x seconds using Python. It was a fun and challenging project that allowed me to learn more about Instagram’s API and how to use Python libraries such as Instaloader and InstaPy. If you want to try it yourself, you can find the code on my GitHub repository here: https://github.com/Ramkishore-sakamuri/Instagram-profile_picture-changer/tree/197f8b8c4b83711126a65742964e693144324f71
I hope you enjoyed reading this blog post and learned something new.