Using Open Source Software to Build Your Instagram Followers

By April 14, 2017 No Comments

I stumbled across InstaPy last week and have been eager to get some time to give it a go. Simply put, it’s an Instagram Like, Comment and Follow Automation Script. Reading through TimG’s post was kind-a inspiring. Through his script, he’s managed to get 2,500+ real followers on Instagram in 4 months, for only ~$5 p/month on hosting fees.

Needless to say, I wanted to see how well it could work for a side project of mine.

Ashamedly, I spent about 1.5hrs fumbling my way through getting it working — primarily because I had no Python experience at all. Eventually I got it up and running, so here’s a guide to help you.

1. Setup a Server

  • Spin up a standard Ubuntu DigitalOcean $10 droplet
    – Important — Chrome (a dependency of InstaPy) didn’t like running on anything less than 1GB ram
    – This literally takes about 2mins with DigitalOcean!
    – Make sure you add your computer’s SSH key, so that you don’t need a username/password
  • SSH into your new box, via ssh root@<IP ADDRESS>
  • Issue the following commands to get the server ready:
# Check for any server updates before we start
sudo apt-get update
# Install unzip, so we can unzip .zip packages
apt install unzip
# Install screen to let scripts run in the
# background, when we close SSH
apt-get install screen
# Install XVFB, for InstaPy
apt install xvfb
# Install Python's package manager
sudo apt-get install python3-pip
# Install Google Chrome, for InstaPy
cd /tmp && wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome-stable_current_amd64.deb
sudo apt-get -f install
# Make python accessible to the command line
sudo ln -s /usr/bin/python3 /usr/bin/python

2. Install InstaPy

  • Create a home for the InstaPy at ~/instapy
mkdir ~/instapy && cd ~/instapy
  • Clone the repo from Git
cd ~/instapy
git clone https://github.com/timgrossmann/InstaPy.git .
  • Run the installer: python setup.py install
  • Download the Chromedriver, placing it into /assets:
cd assets && wget https://chromedriver.storage.googleapis.com/2.33/chromedriver_linux64.zip
#Unzip the package
unzip chromedriver_linux64.zip

3. Create your own InstaPy script

We’ll create our custom script as index.py:

nano ~/instapy/index.py

I wanted to make use of Clarifai’s API, to find Instagram images that may not have actual text defining what it is. Clarifai just know by the photo, what’s in the photo. Cool haha?! Jump over to (you get 5000 API-calls free/month) https://developer.clarifai.com/signup/ and create a free account, once you’re logged in go to https://developer.clarifai.com/account/applications/ and create a new application. You can find the Client ID and Secret there.

Read through the InstaPy docs to see what’s possible, but here’s a default for you to get started:

from instapy import InstaPy
# Config
insta_username = ''
insta_password = ''
comments = [u':thumbsup:', u':punch:', u':raised_hands:', u':point_up:', u':fire:', u':smiley:']
# Setup
session = InstaPy(username=insta_username, password=insta_password, nogui=True)
session.login()
# Comments
session.set_do_comment(True, percentage=33)
session.set_comments(comments)
# Follows
session.set_do_follow(enabled=True, percentage=100, times=1)
# Ignore these
session.set_dont_like(['terrible', 'horrible', 'girl', 'hot'])
# Like Posts
session.like_by_tags(['puppy', 'puppylove', 'puppies'], amount=100)
# Unfollow Users
session.set_dont_unfollow_active_users(enabled=True, posts=5)
session.unfollow_users(amount=100, onlyInstapyFollowed = True, onlyNotFollowMe=True, onlyInstapyMethod = 'FIFO', sleep_delay=20)
# end the bot session
session.end()
  • Test the script: python index.py
    – You can tell it’s working if you start getting output to tell you what it’s doing (eg. Logged in successfully, liked #food etc)

4. Run the Script

Now, let’s keep the script always running in the background, so that we can get back to enjoying life, while InstaPy gets to work.

  • Start a new background screen: screen
    – This will look as though it cleared the terminal, but in fact, it’s essentially opened a new terminal, which will remain open even if you close it
  • Start the InstaPy within the new screen: python ~/index.py
  • Stay with it enough to make sure it’s running, then press “Ctrl+a+d” to detach from the screen. To get back into the screen at any time, simply type the following command screen -r

InstaPy will run through all the commands you’ve set consecutively. Once it’s done that…it’s finished. I saw that my InstaPy script configuration ran for around 22hrs in total. So I needed a way to start it again, when it finished. To do this, I setup a cron (a script which runs at a certain time) to start InstaPy again every 24hrs.

  • Create a shell script: nano ~/instapy/cronstart.sh with the following contents (it literally does the above):
/usr/bin/screen -S <running_screen_id> -X stuff ' python ~/instapy/index.py'`echo -ne '\015'`

*You can get <running_screen_id> with the screen -list command — it’ll show all running screens — just get the numbers before the first . — eg. 1703.pts-0.ubuntu-1gb-sgp1–0

  • Then create a cron, with crontab -e and place the following at the very bottom (this starts the script again at 1am every day):
0 1 * * * /bin/bash ~/instapy/cronstart.sh > ~/instapy/cron.log 2>&1

That’s it. I’ll report back with any findings!