Skip to content

Commit 80bf971

Browse files
HaripriyaBHaripriya Baskaran
authored andcommitted
Made changes to take input from user and readme changes.
1 parent 2bf30f8 commit 80bf971

File tree

3 files changed

+42
-14
lines changed

3 files changed

+42
-14
lines changed

Python/Instagram_Bot/README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,18 @@ The aim is to list all the instagram handles that you follow, that don't follow
1212

1313
`>> pip3 install webdriver-manager`
1414

15-
### **There is a file called `secrets.py` which contains username and password that has to be filled by the user in order to execute the program successfully.**
16-
1715
### Usage:
1816
`>> python instagram_bot.py`
1917

18+
### I/O:
2019

20+
```
21+
Enter Username:$(username)
2122
23+
Enter Password:$(password)
2224
2325
24-
26+
output:
27+
Total unFollowers : $(unfollowers)
28+
<List of unfollowers account ids comes below>
29+
```

Python/Instagram_Bot/instagram_bot.py

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,51 @@
22
from selenium import webdriver
33
from webdriver_manager.chrome import ChromeDriverManager
44
from time import sleep
5-
from secrets import username, password
65

7-
def open_instagram(driver):
6+
username = ""
7+
password = ""
8+
driver = None
9+
10+
def open_instagram():
11+
# set url to driver
812
driver.get("https://instagram.com")
913

10-
def login(driver):
14+
def login():
1115
sleep(2)
16+
# find username field
1217
driver.find_element_by_xpath("//input[@name='username']").send_keys(username)
18+
# find password field
1319
driver.find_element_by_xpath("//input[@name='password']").send_keys(password)
20+
# find Log in button
1421
driver.find_element_by_xpath("//button[@type='submit']").click()
1522
sleep(5)
23+
# click on not now for saving password
1624
driver.find_element_by_xpath("//button[contains(text(), 'Not Now')]").click()
1725
sleep(2)
26+
# click on not now for turning on notifications
1827
driver.find_element_by_xpath("//button[contains(text(), 'Not Now')]").click()
1928
sleep(2)
2029

21-
def get_unfollowers(driver):
30+
def get_unfollowers():
31+
# go to profile page
2232
driver.find_element_by_xpath("//a[contains(@href,'{}')]".format(username)).click()
2333
sleep(5)
34+
# click on following
2435
driver.find_element_by_xpath("//a[contains(@href,'{}/following')]".format(username)).click()
2536
sleep(2)
37+
# Get the list of following accounts
2638
following = get_names(driver)
39+
# click on followers
2740
driver.find_element_by_xpath("//a[contains(@href,'{}/followers')]".format(username)).click()
2841
sleep(2)
42+
# Get the list of followers accounts
2943
followers = get_names(driver)
44+
# compare both lists to find the difference accounts
3045
not_following_back = [user for user in following if user not in followers]
3146
return not_following_back
3247

33-
def get_names(driver):
48+
def get_names():
49+
# keep scrolling till the end of scroll view
3450
scroll_box = driver.find_element_by_xpath("/html/body/div[4]/div/div/div[2]")
3551
last_ht, ht = 0, 1
3652
while last_ht != ht:
@@ -47,10 +63,19 @@ def get_names(driver):
4763
return names
4864

4965
def main():
66+
global username
67+
global password
68+
global driver
69+
# Input from users
70+
username=input("Enter username:")
71+
password=input("Enter password:")
72+
# configuring webdriver
5073
driver = webdriver.Chrome(ChromeDriverManager().install())
51-
open_instagram(driver)
52-
login(driver)
53-
unfollowers = get_unfollowers(driver)
74+
# operations
75+
open_instagram()
76+
login()
77+
unfollowers = get_unfollowers()
78+
# output
5479
print("Total unFollowers : {}\n".format(len(unfollowers)))
5580
for i in unfollowers:
5681
print(i)
@@ -59,4 +84,4 @@ def main():
5984

6085

6186
if __name__ == "__main__":
62-
main()
87+
main()

Python/Instagram_Bot/secrets.py

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)