chatanalyzer/chatanalyzer/participant.py

29 lines
774 B
Python

import ftfy
from datetime import datetime
import string
def remove_punctuations(s):
return s.translate(str.maketrans('', '', string.punctuation))
class Participant:
def __init__(self, name, title, chat_type):
self.name = ftfy.ftfy(name)
self.messages = {}
self.title = ftfy.ftfy(title)
self.chat_type = chat_type
def add_message(self, timestamp, message):
self.messages[str(datetime.fromtimestamp(timestamp/1000))] = ftfy.ftfy(message)
def get_words(self, longer_than=0):
words = []
for m in self.messages.values():
for w in m.split(' '):
if len(w) > longer_than:
words.append(remove_punctuations(w.upper()))
return words