-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfollowStatistics.py
More file actions
62 lines (55 loc) · 1.72 KB
/
followStatistics.py
File metadata and controls
62 lines (55 loc) · 1.72 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
from bs4 import BeautifulSoup
class FollowStatistics:
# Member Variables
numFollowers=0
numFollowing=0
followers=dict()
following=dict()
mutualFollowers=dict()
dontFollowBack=dict()
doesntFollowYou=dict()
# Functions
def printMutuals(self):
mutuals = iter(self.mutualFollowers)
for user in mutuals:
print(user)
return
def printNoFBs(self):
nonFB = iter(self.doesntFollowYou)
for user in nonFB:
print(user)
return
def printUsers(self, userDict):
users = iter(userDict)
for user in users:
print(user)
return
def _initFollowing(self, path):
f = open(path)
soup = BeautifulSoup(f, features="html.parser")
following = soup.find_all("a", class_="FPmhX")
for u in following:
user = u.string
self.following[user]=True
self.numFollowing += 1
return
def _initFollowers(self, path):
f = open(path)
soup = BeautifulSoup(f, features="html.parser")
following = soup.find_all("a", class_="FPmhX")
for u in following:
user = u.string
self.followers[user]=True
self.numFollowers += 1
return
def initTheRest(self, followingPath, followersPath):
self._initFollowing(followingPath)
self._initFollowers(followersPath)
for user in self.followers:
if user in self.following:
self.mutualFollowers[user]=True
else:
self.dontFollowBack[user] = True
for user in self.following:
if user not in self.mutualFollowers:
self.doesntFollowYou[user] = True