Skip to content

Commit

Permalink
fixed all bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
swaaz committed Oct 23, 2020
2 parents f2349b1 + 2e80bc2 commit 6ee5ee0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<h1 align="center"> InstaBot</h1>
<h2 align="center"> Bot built for Instagram using Python and Selenium. </h2>
<h3 align="center">
This is an Instagram bot that can automate and perform some tasks; makes your task easier. The Bot can show the list of un-followers from you Instagram or it can show your fans and also it can cancel all the pending follow requests which you have already sent before or it can aslo unfollow those who don't follow you back.
This is an Instagram bot that can automate and perform some tasks; makes your task easier. The Bot can show the list of un-followers from you Instagram or it can show your fans and also it can cancel all the pending follow requests which you have already sent before or it can also unfollow those who don't follow you back.
</h3>
<div align="center">
<img src="./src/bot.gif" width="300x" height="400px">
Expand Down Expand Up @@ -168,4 +168,4 @@ $ python3 program.py

### Contributers
- [Swaaz](https://github.com/swaaz/)
- [JBLew](https://github.com/autumnlewjb)
- [JBLew](https://github.com/autumnlewjb)
13 changes: 13 additions & 0 deletions program.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class Instabot():

#function to login
def __init__(self,username,password):
"""function to login
input: username, password
output: will login to instagram"""
self.username = username #storing the username in class
self.password = password #storig the password in class
self.driver = webdriver.Firefox(executable_path = "./webdrivers/firefox_webdriver/geckodriver-v0.26.0-linux64/geckodriver") #this is the path of webdriver, here I used geckodriver-linux since I am using Firefox in linux. Change the path of webdriver according to your environment
Expand All @@ -35,6 +38,7 @@ def __init__(self,username,password):

#function to cancel all the pending follow requests
def cancel_sent_requests(self):
"""function to cancel follow pending request"""
self._make_driver_wait("/html/body/div[1]/section/nav/div[2]/div/div/div[1]/a")
self.driver.find_element_by_xpath("/html/body/div[1]/section/nav/div[2]/div/div/div[1]/a").click()
self._make_driver_wait("/html/body/div[1]/section/main/section/div[3]/div[1]/div/div/div[2]/div[1]/div/div/a")
Expand Down Expand Up @@ -79,6 +83,7 @@ def cancel_sent_requests(self):

#function which return the name from the list
def _get_pending_names(self):
"""function which will return names of pending folowers"""
self._make_driver_wait("/html/body/div[1]/section/main/div/article/main")
scroll_box = self.driver.find_element_by_xpath("/html/body/div[1]/section/main/div/article/main")
self._make_driver_wait("-utLf", "class_name")
Expand All @@ -87,6 +92,7 @@ def _get_pending_names(self):

#function to get the names of unfollowers
def get_unfollowers(self):
"""function which will return list of unfollowers"""
self._make_driver_wait("/html/body/div[1]/section/nav/div[2]/div/div/div[1]/a")
self.driver.find_element_by_xpath("/html/body/div[1]/section/nav/div[2]/div/div/div[1]/a").click()
self._make_driver_wait("/html/body/div[1]/section/main/section/div[3]/div[1]/div/div/div[2]/div[1]/div/div/a")
Expand All @@ -98,6 +104,7 @@ def get_unfollowers(self):
self.driver.find_element_by_xpath("//a[contains(@href,'/followers')]").click()
followers = self._get_names()
not_following_back = [user for user in following if user not in followers]
sleep(2)
print("\n****** Unfollowers ******\n")
prev = " "
count = 0
Expand All @@ -109,6 +116,7 @@ def get_unfollowers(self):

#function to get the names of fans
def get_fans(self):
"""function which will return list of fans"""
self._make_driver_wait("/html/body/div[1]/section/nav/div[2]/div/div/div[1]/a")
self.driver.find_element_by_xpath("/html/body/div[1]/section/nav/div[2]/div/div/div[1]/a").click()
self._make_driver_wait("/html/body/div[1]/section/main/section/div[3]/div[1]/div/div/div[2]/div[1]/div/div/a")
Expand All @@ -120,6 +128,7 @@ def get_fans(self):
self.driver.find_element_by_xpath("//a[contains(@href,'/followers')]").click()
followers = self._get_names()
fans = [user for user in followers if user not in following]
sleep(2)
print("\n****** Fans ******\n")
prev = " "
count = 0
Expand All @@ -131,6 +140,7 @@ def get_fans(self):

#function which returns list of names
def _get_names(self):
"""function which will return list of names"""
# TODO: The app might still change in future. If timeout exception happens again, just change the path of the elements below.
self._make_driver_wait("/html/body/div[4]/div/div/div[2]")
scroll_box = self.driver.find_element_by_xpath("/html/body/div[4]/div/div/div[2]")
Expand All @@ -148,9 +158,11 @@ def _get_names(self):
self._make_driver_wait("/html/body/div[4]/div/div/div[1]/div/div[2]/button")
self.driver.find_element_by_xpath("/html/body/div[4]/div/div/div[1]/div/div[2]/button").click()
return names
sleep(2)

#function cancel unfollowers
def cancel_unfollowers(self):
"""function which will cancel unfollowers"""
self._make_driver_wait("/html/body/div[1]/section/nav/div[2]/div/div/div[1]/a")
self.driver.find_element_by_xpath("/html/body/div[1]/section/nav/div[2]/div/div/div[1]/a").click()
self._make_driver_wait("/html/body/div[1]/section/main/section/div[3]/div[1]/div/div/div[2]/div[1]/div/div/a")
Expand Down Expand Up @@ -181,6 +193,7 @@ def cancel_unfollowers(self):
continue

def Exit(self):
"""function to logout"""
self._make_driver_wait("/html/body/div[1]/section/nav/div[2]/div/div/div[1]/a")
self.driver.find_element_by_xpath("/html/body/div[1]/section/nav/div[2]/div/div/div[1]/a").click()
self._make_driver_wait("/html/body/div[1]/section/main/section/div[3]/div[1]/div/div/div[2]/div[1]/div/div/a")
Expand Down

0 comments on commit 6ee5ee0

Please sign in to comment.