This repository has been archived by the owner on Sep 27, 2020. It is now read-only.
forked from Pavitheran/FBMessageScraper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_stats.py
140 lines (108 loc) · 3.82 KB
/
get_stats.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
import json
from pprint import pprint
from collections import defaultdict
id_mapping = {
'fbid:706676557': "Rogges",
'fbid:584246322': "Vinoth",
'fbid:100003250438654': "Aushvin",
'fbid:100003581697251': "Thannoj",
'fbid:1112575489': "Janusshan",
'fbid:1345872565': "Arrjun",
'fbid:531215673': "Ali Nawed",
'fbid:1184441679': "Ewan",
'fbid:612562487': "Keerthijan",
'fbid:100003725285733': "Harris",
'fbid:100000361213110': "Pavi",
'fbid:747570870': "Javed",
'fbid:100002441596551': "Kishan",
'fbid:667097178': "Maaz",
'fbid:776766826': "Hamza",
'fbid:1031445696': "Sabil",
'fbid:1070425055': "Saad"
}
def getKey(item):
return item[1]
# Who sends the most messages?
msg_count = defaultdict(int)
with open('message_data.json') as msg_data:
data = json.load(msg_data)
msgs = data["messages"]
print "Total Messages: " + str(len(msgs))
for msg in msgs:
msg_count[id_mapping[msg["author"]]] += 1
print "Message Counts: "
print sorted(msg_count.items(), key=getKey, reverse=True)
# Who swears the most adjusted for how often they message?
swear_words = set(["replace with list of swear words"])
# How often do each of us say "bro" adjusted for how often they message?
# Should have used regex in hindsight
bros = set(["bro", "broo", "brooo", "broooo", "brooooo",
"broooooo", "brooooooo", "broooooooo", "brooooooooo", "broooooooooo"])
swear_count = defaultdict(int)
bro_count = defaultdict(int)
with open('message_data.json') as msg_data:
data = json.load(msg_data)
msgs = data["messages"]
for msg in msgs:
text = msg["body"].lower().split()
for word in text:
if word in swear_words:
swear_count[id_mapping[msg["author"]]] += 1
if word in bros:
bro_count[id_mapping[msg["author"]]] += 1
print "Biggest, baddest sailor: "
print sorted(swear_count.items(), key=getKey, reverse=True)
adjusted_swear = {}
for key in swear_count:
adjusted_swear[key] = 1.0 * swear_count[key] / msg_count[key]
print "Normalized swear count: "
print sorted(adjusted_swear.items(), key=getKey, reverse=True)
print "Biggest Bro: "
print sorted(bro_count.items(), key=getKey, reverse=True)
adjusted_bro = {}
for key in bro_count:
adjusted_bro[key] = 1.0 * bro_count[key] / msg_count[key]
print "Normalized bro count: "
print sorted(adjusted_bro.items(), key=getKey, reverse=True)
# Who's name gets mentioned the most?
names = set(["ali", "javed", "nawed", "rogges", "janu",
"janusshan", "av", "aushvin", "saad", "hamza",
"pavi", "arrjun", "harris", "haris", "kishan",
"kish", "sabil", "daas", "thannoj", "yeaser", "maaz", "vinoth"])
# Which school do we talk about the most?
schools = set(["waterloo", "uoft", "york", "schulich",
"ryerson", "uwaterloo", "utoronto", "utsc", "utsg",
"uw", "queens"])
popular = defaultdict(int)
school_count = defaultdict(int)
with open('message_data.json') as msg_data:
data = json.load(msg_data)
msgs = data["messages"]
for msg in msgs:
text = msg["body"].lower().split()
for word in text:
if word in names:
popular[word] += 1
if word in schools:
school_count[word] += 1
print "Most popular person: "
print sorted(popular.items(), key=getKey, reverse=True)
print "Most popular school: "
print sorted(school_count.items(), key=getKey, reverse=True)
# Percentage of the time ppl message from web/messenger?
# Pie chart would be perfect for this
device = defaultdict(int)
# What was our most active day on facebook?
day_count = defaultdict(int)
with open('message_data.json') as msg_data:
data = json.load(msg_data)
msgs = data["messages"]
for msg in msgs:
device[msg["source"]] += 1
day_count[msg["timestamp_absolute"]] += 1
print "How we send our messages: "
print sorted(device.items(), key=getKey, reverse=True)
print "Our most active days on Facebook: "
print sorted(day_count.items(), key=getKey, reverse=True)[:10]
print "Our least active days on Facebook: "
print sorted(day_count.items(), key=getKey)[1:10]