-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodes.py
More file actions
78 lines (60 loc) · 2.89 KB
/
modes.py
File metadata and controls
78 lines (60 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from selenium import webdriver
import os
from time import localtime, sleep
import sys
from actions import find_followers_or_following, you_follow_them_but_they_not_you_check, unfollow_some_of_them_do_it
from operations import read_file, write_file, users_to_look
def login(browser):
if ("insta_username" not in os.environ) or ("insta_password" not in os.environ):
print("Please export insta_username and insta_password")
browser.quit()
sys.exit(1)
credentials = {"username":os.environ['insta_username'], "password":os.environ['insta_password']}
username = browser.find_element_by_name("username")
username.send_keys(credentials["username"])
sleep(1)
password = browser.find_element_by_name("password")
password.send_keys(credentials["password"])
sleep(1)
submit = browser.find_element_by_css_selector("[type='submit']")
submit.click()
sleep(5)
return credentials["username"]
def you_follow_them_but_they_not_you(browser):
users_names = users_to_look()
for i in users_names:
browser.get("https://www.instagram.com/"+i)
sleep(2)
followers = find_followers_or_following(browser, i, "followers")
print(i, "has", len(followers), "followers.")
write_file("files/"+ i +"_followers.json", followers) # for debuging reasons
browser.get("https://www.instagram.com/"+i)
sleep(1)
following = find_followers_or_following(browser, i, "following")
print(i, "is following", len(following), "people.")
write_file("files/"+ i +"_following.json", following) # for debuging reasons
ret = you_follow_them_but_they_not_you_check(followers,following)
ret.sort()
write_file("files/"+ i +"_you_follow_them_but_they_not_you.json", ret) # for debuging reasons
print("You follow them but not them you for user: ", i)
print(ret)
sleep(5)
return ret #needed for unfollow
def unfollow_script(browser, username, find_followers, count):
if find_followers:
browser.get("https://www.instagram.com/"+username)
sleep(2)
followers = find_followers_or_following(browser, username, "followers")
print(username, "has", len(followers), "followers.")
write_file("files/"+ username +"_followers.json", followers) # for debuging reasons
followers = set(followers)
else:
followers = set(read_file("files/"+ username +"_followers.json"))
unfollowed = unfollow_some_of_them_do_it(browser, username, int(count), followers)
print(username, "just unfollowed", len(unfollowed), "people.")
if os.path.exists("files/"+ username +"_unfollowed.json"):
unfollowed_so_far = read_file("files/"+ username +"_unfollowed.json")
else:
unfollowed_so_far = []
unfollowed = unfollowed_so_far + unfollowed
write_file("files/"+ username +"_unfollowed.json", unfollowed) # for debuging reasons