-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparticipant.py
73 lines (59 loc) · 2.72 KB
/
participant.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
import emoji
import datetime
class Content():
def __init__(self, content):
self.type = content
self.total = 0
self.period ={ 'year' : {}, 'month' : {}, 'week_number' : {},
'month_day' : {}, 'week_day' : {}, 'hour' : {},
'date' : {}, 'year-week_number' : {}}
def add_entry(self, timestamp, multiple_entries=0, datetime_object=False):
"""Adds time entries to given type of content.
"""
# Converts timestamp to format without miliseconds
if multiple_entries:
count = multiple_entries
else:
count = 1
self.total += count
if not datetime_object:
timestamp = int(str(timestamp)[:-3])
time = datetime.datetime.fromtimestamp(timestamp)
else:
time = timestamp
time = time.strftime("%Y %B %W %d %A %H %d/%m/%y %Y:%W").split(' ')
for interval in self.period:
x = time.pop(0)
self.period[interval][x] = self.period[interval].get(x, 0) + count
class Participant():
def __init__(self, name):
self.name = name
self.content = {'photos' : Content('photos'), 'videos' : Content('videos'),
'audio_files' : Content('audio_files'),
'gifs' : Content('gifs'), 'sticker' : Content('sticker'),
'share' : Content('share'),'reactions' : Content('reactions'),
'messages' : Content('reactions'), 'words' : Content('words'),
'emojis' : Content('emojis'), 'swearing' : Content('swearing')}
self.most_common_words = {}
def add_message(self, message):
"""Analyses given message.
"""
timestamp = message['timestamp_ms']
for item in['photos', 'videos', 'gifs', 'share', 'audio_files', 'sticker']:
if item in message:
self.content[item].add_entry(timestamp)
self.content['words'].total -= 4
if 'reactions' in message:
self.content['reactions'].add_entry(timestamp,len(message['reactions']))
# If you want to get statistics of swearings, put the words as strings
# into the list swearings
swearings = []
if 'content' in message:
self.content['messages'].add_entry(timestamp)
text = message['content']
self.content['words'].add_entry(timestamp, len(text.split(' ')))
if emoji.emoji_count(text):
self.content['emojis'].add_entry(timestamp, emoji.emoji_count(text))
for vulgarism in swearings:
if vulgarism in text.lower():
self.content['swearing'].add_entry(timestamp)