-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
162 lines (132 loc) · 5 KB
/
main.py
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import atexit
import json
try:
from colorama import Style, Fore
except ImportError:
print('\n\n"colorama" is nedded for the operation of this code!')
print('Please install it by running: "pip install colorama"\n\n')
exit()
from utils import error, info, printColored, clearCLI
# Resets text color and style when the code exits
atexit.register(lambda: print(Style.RESET_ALL))
def loadJSONs():
success = True
followers, followings, whitelist = None, None, None
# Open followers and following jsons.
try:
with open("./followers_1.json") as file:
data = json.load(file)
followers = list(
(follower["string_list_data"][0]["value"] for follower in data)
)
except FileNotFoundError:
error(
'You need to have "followers_1.json" on the same folder as the executable. For more, read the README.'
)
success = False
except json.JSONDecodeError:
error('The file "followers_1.json" is not formatted correctly.')
success = False
try:
with open("./following.json") as file:
followings = list(
following["string_list_data"][0]["value"]
for following in json.load(file)["relationships_following"]
)
except FileNotFoundError:
error(
'You need to have "following.json" on the same folder as the executable. For more, read the README.'
)
success = False
except json.JSONDecodeError:
error('The file "following.json" is not formatted correctly.')
success = False
# Open or create the whitelist json
try:
with open("./whitelist.json") as file:
data = json.load(file)
if data is list:
error(
'The file "whitelist.json" is not formatted correctly. It should be a list.'
)
success = False
else:
whitelist = list(tag for tag in data)
except FileNotFoundError:
with open("./whitelist.json", "w") as file:
file.write('[\n\t"INSERT_HERE_THE_ACCOUNTS_YOU_DON\'T_WANNA_CHECK_ON"\n]')
info(
'whitelist.json has been created. Write in "whitelist.json" the accounts you don\'t wanna check on.\n'
)
with open("./whitelist.json") as file:
whitelist = list(tag for tag in json.load(file))
except json.JSONDecodeError as e:
print(e)
error('The file "whitelist.json" is not formatted correctly.')
success = False
return followers, followings, whitelist, success
def compareLists():
followers, followings, whitelist, success = loadJSONs()
if not success:
return
# Compare lists
nUnfollorers = 0
for following in followings:
if following not in followers and following.lower() not in tuple(
user.lower() for user in whitelist
):
nUnfollorers += 1
print(
f"{(len(str(len(followings)))-len(str(nUnfollorers))) * ' '}{nUnfollorers}. {Fore.RED}{Style.BRIGHT}"
f"{following.upper()}{Style.RESET_ALL} {(len(max(followings))+2-len(following)) * ' '}"
"doesn't follow you back."
)
if nUnfollorers == 0:
printColored("Congotulations! Everybody follows you back.", Fore.GREEN)
def printWhitelist():
whitelist, success = loadJSONs()[2:]
if not success:
return
if "INSERT_HERE_THE_ACCOUNTS_YOU_DON'T_WANNA_CHECK_ON" in whitelist:
whitelist.remove("INSERT_HERE_THE_ACCOUNTS_YOU_DON'T_WANNA_CHECK_ON")
if len(whitelist) == 0:
info("The whitelist is empty")
else:
for i in whitelist:
print(f" - {Fore.GREEN}{Style.BRIGHT}{i}{Style.RESET_ALL}")
def about():
printColored(
"Code written by Smartsv (SmartsvXD on Github)\n\nItaly, 2024", Fore.GREEN
)
def main():
actions = {
"Find unfollowers": compareLists,
"Print whitelist": printWhitelist,
"About": about,
f"{Fore.RED}Exit{Fore.RESET}": exit,
}
prevInputInvalid = 0
while 1:
clearCLI()
print(f"{Fore.MAGENTA}{Style.BRIGHT}Welcome to InstaUnfollowerFinder by Smartsv!{Style.RESET_ALL}\n")
# Print all the actions
for n, i in enumerate(actions.keys()):
print(f" {n+1}. {Style.BRIGHT}{i}{Style.RESET_ALL}")
print()
# Print something if the previrous input was not valid
if prevInputInvalid:
printColored("Invalid input!", Fore.RED)
prevInputInvalid = 0
# Ask and run user input
try:
selection = (
int(input(f"{Fore.YELLOW}Select what you wanna do: {Fore.RESET}")) - 1
)
clearCLI()
tuple(actions.values())[selection]()
input(
f"{Fore.YELLOW}{Style.DIM}\n(Press ENTER to go back to menu){Style.RESET_ALL}"
)
except (IndexError, ValueError):
prevInputInvalid = 1
main()