-
Notifications
You must be signed in to change notification settings - Fork 0
/
haha.py
52 lines (45 loc) · 1.55 KB
/
haha.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
import matplotlib.pyplot as plt
import sys
def get_valid_lines(path, user):
with open(path, "r", encoding="utf8") as f:
lines = f.readlines()
return filter_lines(lines, user)
def filter_lines(lines, user):
filtered_lines = []
for line in lines:
if line.endswith("<Media omitted>") or not check_user(line, user):
continue
else:
split_line = line.split(": ")
if(len(split_line) > 1 and split_line[1].startswith("http")):
continue
else:
filtered_lines.append(line)
return filtered_lines
def check_user(line, user):
split_line = line.split(" - ")
if len(split_line) > 1 and split_line[1].startswith(user):
return True
return False
def count_categorize_lines(lines):
nrof_haha = 0
nrof_xd = 0
nrof_normal = 0
for line in lines:
if line.endswith("xD\n") or line.endswith("xd\n"):
nrof_xd+=1
elif(line.endswith("haha\n")):
nrof_haha+=1
else:
nrof_normal+=1
return nrof_haha, nrof_xd, nrof_normal
def plot_categories(nrof_haha, nrof_xd, nrof_normal):
labels = "haha", "xd", "Other"
sizes = [nrof_haha, nrof_xd, nrof_normal]
fig1, ax1, = plt.subplots()
ax1.pie(sizes, labels=labels, autopct="%1.1f%%", shadow=True, startangle=90)
ax1.axis("equal")
plt.show()
if __name__ == "__main__":
nrof_haha, nrof_xd, nrof_normal = count_categorize_lines(get_valid_lines(sys.argv[1], sys.argv[2]))
plot_categories(nrof_haha, nrof_xd, nrof_normal)