mirror of
https://github.com/StefBuwalda/whatsapp-wordcloud.git
synced 2025-10-30 11:19:57 +00:00
refactoring
This commit is contained in:
28
backend/process_data.py
Normal file
28
backend/process_data.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from os import makedirs
|
||||
from backend.functions import (
|
||||
processRawMessages,
|
||||
processMessageList,
|
||||
)
|
||||
from collections import Counter
|
||||
|
||||
|
||||
# Open and read the chats from the '/data/_chat.txt' file exported by Whatsapp
|
||||
try:
|
||||
file = open("data/_chat.txt", encoding="utf8")
|
||||
chat = file.read()
|
||||
file.close()
|
||||
except FileNotFoundError:
|
||||
print("Sorry, the file /data/_chat.txt does not exist.")
|
||||
exit()
|
||||
|
||||
makedirs("output", exist_ok=True)
|
||||
|
||||
test = processRawMessages(chat)
|
||||
|
||||
frequency_dictionary: dict[str, dict[str, int]] = {}
|
||||
|
||||
for author in test.keys():
|
||||
frequency_dictionary[author] = {}
|
||||
messageList = test.get(author)
|
||||
if messageList:
|
||||
frequency_dictionary[author] = Counter(processMessageList(messageList))
|
||||
Reference in New Issue
Block a user