Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding option to find users who don't follow the target back #344

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ def cmdlist():
print("Get a list of user who commented target's photos")
pc.printout("wtagged\t\t")
print("Get a list of user who tagged target")
pc.printout("nfollowback\t\t")
print("Get a list of users who don't follow back target")


def signal_handler(sig, frame):
Expand Down Expand Up @@ -149,7 +151,8 @@ def _quit():
'tagged': api.get_people_tagged_by_user,
'target': api.change_target,
'wcommented': api.get_people_who_commented,
'wtagged': api.get_people_who_tagged
'wtagged': api.get_people_who_tagged,
'nfollowback': api.get_not_follows_back,
}


Expand Down
97 changes: 97 additions & 0 deletions src/Osintgram.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,103 @@ def get_followings(self):
json.dump(json_data, f)

print(t)

def get_not_follows_back(self):
if self.check_private_profile():
return

pc.printout("Searching for target followers...\n")
_followers = []
rank_token = AppClient.generate_uuid()
data = self.api.user_followers(str(self.target_id), rank_token=rank_token)

_followers.extend(data.get('users', []))

next_max_id = data.get('next_max_id')
while next_max_id:
sys.stdout.write("\rCatched %i followers" % len(_followers))
sys.stdout.flush()
results = self.api.user_followers(str(self.target_id), rank_token=rank_token, max_id=next_max_id)
_followers.extend(results.get('users', []))
next_max_id = results.get('next_max_id')

print("\n")

pc.printout("Searching for target followings...\n")

_followings = []

rank_token = AppClient.generate_uuid()
data = self.api.user_following(str(self.target_id), rank_token=rank_token)

_followings.extend(data.get('users', []))

next_max_id = data.get('next_max_id')
while next_max_id:
sys.stdout.write("\rCatched %i followings" % len(_followings))
sys.stdout.flush()
results = self.api.user_following(str(self.target_id), rank_token=rank_token, max_id=next_max_id)
_followings.extend(results.get('users', []))
next_max_id = results.get('next_max_id')

print("\n")
not_follows_back = []
followers_usernames = []
followings_usernames = []
for user in _followings:
followings_usernames.append(user["username"])

for user in _followers:
followers_usernames.append(user["username"])


follows_back = set(followings_usernames).intersection(followers_usernames)

_not_follows_back = _followings.copy()

for username in follows_back:
_not_follows_back[:] = [d for d in _not_follows_back if d.get('username') != username]

for user in _not_follows_back:
u = {
'id': user['pk'],
'username': user['username'],
'full_name': user['full_name']
}
not_follows_back.append(u)

t = PrettyTable(['ID', 'Username', 'Full Name'])
t.align["ID"] = "l"
t.align["Username"] = "l"
t.align["Full Name"] = "l"

json_data = {}
not_follows_back_list = []

for node in not_follows_back:
t.add_row([str(node['id']), node['username'], node['full_name']])

if self.jsonDump:
follow = {
'id': node['id'],
'username': node['username'],
'full_name': node['full_name']
}
not_follows_back_list.append(follow)

if self.writeFile:
file_name = self.output_dir + "/" + self.target + "_does_not_follow_back.txt"
file = open(file_name, "w")
file.write(str(t))
file.close()

if self.jsonDump:
json_data['notfollowsback'] = not_follows_back_list
json_file_name = self.output_dir + "/" + self.target + "_does_not_follow_back.json"
with open(json_file_name, 'w') as f:
json.dump(json_data, f)

print(t)

def get_hashtags(self):
if self.check_private_profile():
Expand Down