Creating an Instagram bot(using Python and Streamlit)

Ujjayanta Bhaumik
2 min readMay 28, 2021

Today, I would tell you how to create a simple Instagram bot using Python. You will also get to know how to create a simple GUI for the bot using streamlit 😄

So, what does the bot do? The bot simply outputs the name of the users (whom you follow) who don’t follow you back 😆 Also, you could do this for any user you want(just need the Insta username)

Libraries used: Streamlit, Instaloader

Let’s start then.

import instaloader
username = 'Put your username inside this quote'
password = 'Put your password inside this quote'
L = instaloader.Instaloader()
# Login or load session
L.login(username, password)#this should be your own username and #password
profile = instaloader.Profile.from_username(L.context, username)
# in the line above, replace the username field by the username of #the person you want this bot to work for. If you want to find the #list of persons who do not follow you back, replace username by #your own username. If you want for someone else, use their #username.
main_followers = profile.followers
follower_list = [] #people who follow you
for person in profile.get_followers():
user_id = person.userid
follower_list.append(person.username)
main_followees = profile.followees
followee_list = [] #people whom you follow
for person in profile.get_followees():
user_id = person.userid
followee_list.append(person.username)
req = []for element in followee_list:
if element not in follower_list:
req.append(element)
print(sorted(req))

You can find this file in Colab and run it directly: Instabot

 https://colab.research.google.com/drive/1U7O-j--PiVDOyPzW-SHcb6hl4oj1Jkim?usp=sharing

The Streamlit implementation is here:

import streamlit as st
import instaloader
st.header("Your friendly neighborhood Instabot")
name = st.text_input("Enter user name")
password = st.text_input("Enter password")
L = instaloader.Instaloader()if st.button('Get Ghost list'):
# Login or load session
L.login(name, password) # (login)
profile = instaloader.Profile.from_username(L.context, name)
main_followers = profile.followers
follower_list = []
for person in profile.get_followers():
user_id = person.userid
follower_list.append(person.username)

main_followees = profile.followees
followee_list = []
for person in profile.get_followees():
user_id = person.userid
followee_list.append(person.username)

req = []
for element in followee_list:
if element not in follower_list:
req.append(element)

st.write(sorted(req))

To run the streamlit app:

  • save the above code in a file app.py
  • open the command prompt and type this command: streamlit run app.py

The resultant bot 🎃

--

--

Ujjayanta Bhaumik

MSc Computer Vision, Graphics and Imaging, University College London