-
Notifications
You must be signed in to change notification settings - Fork 5
/
twitter_followers_stats_set.py
40 lines (38 loc) · 1.63 KB
/
twitter_followers_stats_set.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
import sys
import json
import time
def usage():
print("Usage: ")
print("python {} <username>".format(sys.argv[0]))
if __name__ == '__main__':
if len(sys.argv) != 2:
usage()
sys.exit(1)
screen_name = sys.argv[1]
followers_file = "Twitter_Profiles/{}/followers.jsonl".format(screen_name)
friends_file = "Twitter_Profiles/{}/friends.jsonl".format(screen_name)
with open(followers_file) as f1, open(friends_file) as f2:
t0 = time.time()
followers = set()
friends = set()
for line in f1:
profile = json.loads(line)
followers.add(profile['screen_name'])
for line in f2:
profile = json.loads(line)
friends.add(profile['screen_name'])
t1 = time.time()
mutual_friends = friends.intersection(followers)
followers_not_following = followers.difference(friends)
friends_not_following = friends.difference(followers)
t2 = time.time()
print("------TIMING-----")
print("Initialize data: {}".format(t1-t0))
print("Set-based operations: {}".format(t2-t1))
print("Total time: {}".format(t2-t0))
"""print("-------STATISTICS-------")
print("{} has {} followers".format(screen_name, len(followers)))
print("{} is following {} friends".format(screen_name, len(friends)))
print("{} has {} mutal followers".format(screen_name, len(mutual_friends)))
print("{} friends are not following {} back".format(len(friends_not_following), screen_name))
print("{} is not following {} of his followers".format(screen_name, len(followers_not_following)))"""