-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2_compare.py
35 lines (29 loc) · 1.45 KB
/
2_compare.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
# Function to read usernames from a text file and return a set
def read_usernames_from_file(file_path):
with open(file_path, 'r', encoding='utf-8') as file:
return set(line.strip() for line in file.readlines())
# Paths to the extracted usernames files
followers_file_path = 'extracted_followers_usernames.txt' # output of 1_filtering.py
following_file_path = 'extracted_following_usernames.txt' # output of 1_filtering.py
# Read the usernames from both files
followers = read_usernames_from_file(followers_file_path)
following = read_usernames_from_file(following_file_path)
# Find users you follow but who do not follow you back
not_following_back = following - followers
# Sort the usernames in alphabetical order
sorted_not_following_back = sorted(not_following_back)
# Output the list of users who don't follow you back
if sorted_not_following_back:
print("Users you follow but who don't follow you back:")
# for username in sorted_not_following_back:
# print(username)
else:
print("Everyone you follow follows you back!")
# Optionally, save the sorted list to a file
with open('not_following_back.txt', 'w') as output_file:
if sorted_not_following_back:
output_file.write('\n'.join(sorted_not_following_back))
print("List of users not following back saved to not_following_back.txt")
else:
output_file.write("Everyone you follow follows you back!")
print("No one to save in not_following_back.txt")