Insu — Instagram Bot.
Making of INSU Part 2
In the first part, we had conversed about the whole principle sort of stuff. Now we have to add a loop and other things like user input, etc. (Want to read first then click here.)
At the bottom of this page, you will get the full code and a GitHub link to this project also.
Let’s Begin with user input.
import time
import pyautogui as pg
from pyfiglet import Figlet
f = Figlet(font='doom')
print(f.renderText('InSu'))
print("------------------------------Namaste------------------------------------")
print("----------------(Insu(v0.5) Instagram Bot by likenull)-------------------")
The above code is just for embellishment.
count = 0
numlikes = int(input("How many post to like: "))
print(str(numlikes) + " posts to like")
print()
hastag = str(input("Hashtag to use:"))
print("Using hashtag: " + str(hastag))
print()
print("Launching(slow mode)...")
Here, we have taken two inputs 1st is “numlikes” in which users have to provide how many posts does user wants to like.
And the second one is “hastag” in which users have to write which hashtag the user want to go with.
Then there is some printing stuff that will let the user know their inputs.
And we have also introduced here “count” which we will use in the loop function.
Now the below code is the code we had created in the previous post which insu will use to browse Instagram to like posts.
time.sleep(2)
pg.click(236, 98)
pg.write(hastag)
print()
pg.PAUSE = 3.25
pg.press('down')
pg.PAUSE = 2.0
pg.press('enter')
pg.press('enter')
pg.PAUSE = 3.6
pg.press('pagedown')
#Step 2 post click
pg.PAUSE = 2.0
pg.click(98, 518)
pg.PAUSE = 3.0
#alinging pointer to the middle Point(x=339, y=400)
print("Liking recent Post by tag.....")
print()
pg.moveTo(332, 400)
pg.Pause = 2.0
pg.doubleClick(332, 400)
print("First post liked")
print()
As you can see above code contains sleep which we have employed to let the page load first if you got a more lagging internet speed then you can increase them or if you have a fast internet speed then you can reduce them. The overhead code will take us to the first “recent post” to like using the hashtag user have fed, and will also like the first post and then it will print “First post liked”.
Now let’s utilise the while loop to like the number of posts described by the user.
print("************************************************************************")
pg.Pause = 3.5
pg.press('right')
count = 1
while (count < numlikes):
count = count + 1
pg.doubleClick(332, 400)
pg.Pause = 4.0
pg.press('right')
print("\rPosts liked: "+str(count), end='')
pg.Pause = 0.1else:
print("********************************************************************")
print()
print(str(numlikes) +" Post liked. By tag" + str(hastag))#print(screensize)
#print(pointer)
Here we have used “pg.press(‘right’)” to press right on the computer(keyboard output) so that the next post will appear to like. and we are using pause also to provide some time to Instagram to load the next post. And “count” is updated before liking every single post so the this will loop will run until “count” is smaller than numlikes.
print("\rPosts liked: "+str(count), end='')
The above code doesn’t work everywhere, this code changes the previous data of the number of liked posts. but this doesn’t work in idle and in IDE’s this only work when you use “python.exe” I mean you have to use python in cmd to make it work. But this doesn’t influence the function it just makes it look wired but if you run this in Cmd then you can see this printing method works fine.
If you don’t want to use this print method then you can just use “print(“Post liked =” + str(count))”
this will give no error but will print the number of posts liked in a new line whenever a post is liked.
Now that’s all for the coding part if you are facing errors like insu scrolling page at the wrong moment, and if your code is double-clicking the wrong time. Then you can modify the sleep value to resolve them.
And I prefer you to first go to Instagram and clear searches and then search for the hashtag you want to like then let it load. And after this go back to the Instagram home page and then start Insu. This will help you because your browser would have saved the cache of that page and will load faster.
Conclusion: Insu has both pros and cons. For instance:-
Cons:
1.A little bit complex to code.
2.Differs screen to screen.
3.Less variety of functions.
Pros:
1.Easy to use.
2.Instagram/Browser wouldn’t that bot was used. (because we have provided mouse and keyboard outputs to browser the website like a human.)
3.No uncertainty with Instagram updates.
4.No use of complex APIs and extensions which may fall apart in the future.
5.And was fun to code.
Thank You, guys.
And if you are facing any problem or want my help then you can mail me at contactlikenull@gmail.com or you can use Github and Instagram to contact me.
Here is the full code and GitHub project link.
Originally published at https://www.codelikenull.com by codelikenull.
