Project 001 | Instagram Automation Tool
Automated Instagram Tool. Year: 2020
Language: Python
Inspiration: I wanted to create something that would also be useful to me as a photographer. I figured if I could automate instagram activity it could boost my exposure as a photographer as well as increase my coding skills.
Research: I discovered many resources were available online to aid in the creation of various instagram automation tools, however all of the tutorials and resources were written in python.
Step 1: Learn python - I discovered the YouTube channel ‘CodewithMosh’ and utilised the very well made tutorials to learn all of the basics of python. From if statements to classes and modules.
Step 2: Get started - I used a YouTube tutorial which helped me to create an initial class with a login method which I could customise with the username / password from my own account.
Step 3: Plan and execute - it became clear this program will be quite complicated, so I created an extensive plan of which features I would create and how I would create them along with clarifying the scope of how I would like it to be used.
Scope: I decided I wanted to be able to deploy the program on the cloud so it could work continuously and uninterrupted without my intervention.
Then I decided on the following functionality:
Login:
Opens an automated browser via selenium and inputs the customisable username and password.
The program then begins a cycle, it will theoretically continue to repeat on an infinite loop.
CYCLE START
Target account:
Randomly selects from a list of accounts designated as targets by the user (ideally accounts similar to that of the user), this feature also checks if targeted account is still active - and if not navigate to another account at random.
Create instagram user list:
Scrape a list of followers from targeted account into a “to_follow” list and dump them into an external json file, so the data of said list will be persistent in case of a software failure.
Note: since these followers already follow a similar account to the users, there is a high likelyhood they will be interested in the users account also.
Target users in list:
The program will now individually navigate to each of the users accounts in the “to_follow” json list and carry out the following features:
Like:
This feature randomly targets between 1-3 of the users 9 most recent images and likes them. Throwing an
exception if image does not exist.
Follow:
This feature then follows the current user.
Cleanup:
This feature then deletes the previously targeted user from the instagram user list, so they aren’t targeted
again and also adds them to a ‘previously followed’ list to avoid them being targeted again in future cycles
and also a “following” list , which is utilised by a subsequent feature called unfollow.
Unfollow:
This feature only turns after a follow cycle has completed and also only if the “following” list has a length
greater than 500. If both of these conditions are met, this feature will periodically visit each instagram user
on the following list and unfollow them, whilst simultaneously deleting them from the following list.
CYCLE END
After all of the above processes have been completed then the program will rest for a random period of time so as to simulate normal human activity, and generally start again the following morning. Actually the “sleep(uniform(X,Y))” method is used extensively throughout the program so as to continuously simulate normal human behaviour. Also worth noting all lists are saved in persistent storage so nothing is lost in the event of a program crash or failure. ]
RESULTS
I ran this software for a period of 6 weeks on both my own and a friends account with surprisingly good results. My friend received over 1400 followers and obtained 3 real world consultations + subsequent income of £320 for her cosmetics business, based purely on the program and I obtained over 600 followers for my own instagram, although the reduction of results for my own account is likely due to the fact I ran the program on my own account more sporadically.
I discovered around 20% of targeted users followed back and around 25% engaged with the users account in some way. Dramatically exceeding my expectations.
AFTERWORD
Although the program largely met its objectives, and seemed to offer valuable real world results. I did receive warnings from instagram on my friends account after 6 weeks. Explaining that it was concerned the account was being automated in some way. At this point I discovered that the software was in some way infringing upon instagram terms and conditions and decided to discontinue the project.
The code is now broken, since instagram has changed the path to seemingly all of the elements which the program operates on and I do not see value in updating the program to the new element paths.
I would also like to note, my grip on python was at the time rudimentary and although I did employ basic princicples such as DRY (dont repeeat yourself), and keeping each class method modular and isolated from the rest of the code... I could have certainly improved in other aspects such as replacing many while loops with for loops, abstracting the username / password info and seperating other parts of the code into different files to make it easier to understand and edit.
Short screen recording of basic functionality in action !
Here is a link to the main code on github:
Get in touch at jobs@josephrigby.com