-
Notifications
You must be signed in to change notification settings - Fork 0
/
whats_app_chat_util.py
52 lines (31 loc) · 1.2 KB
/
whats_app_chat_util.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 emoji
from collections import defaultdict
def extract_text_data(path):
file = open(path, 'r', encoding='utf8')
out_file = open('output.txt', 'w', encoding='utf8')
lines = [line for line in file]
#lines = lines[:100]
#dd = defaultdict(lambda: 0)
for line in lines:
line = line[:-1] # ommiting the new line character at the end of the sentance
# text is in format of
# [30.10.22., 12:45:32] Sender Name: Some text message: it could contain two dots
# SO there 3 ':' signs before text msg, but text msg itself could contain :
txt_split_on_two_dots = line.split(':')
text_msg = ':'.join(txt_split_on_two_dots[3:])
text_msg = text_msg[1:] # Omitting the starting space after :
text_msg = emoji.replace_emoji(text_msg, '') # Removing emojis
if 'omitted' in text_msg:
continue
if len(text_msg) == 0:
continue
if '' in text_msg:
continue
out_file.write(text_msg + '\n')
print(text_msg)
#print(dict(dd))
def main():
path = 'aca_chat/chat.txt'
extract_text_data(path)
if __name__ == "__main__":
main()