# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

import pandas as pd
import regex as re
import numpy as np
from collections import Counter
import matplotlib.pyplot as plt
import emoji
from wordcloud import WordCloud, STOPWORDS, ImageColorGenerator


# +
def is_date_time(s):
    pattern = '^([0-9]{2})(\/)([0-9]{2})(\/)([0-9]{2,4}), ([0-9]+):([0-9]+)[ ]?(AM|PM|am|pm)? - '
    result = re.match(pattern,s)
    if result:
        return True
    else:
        return False
def is_author(s):
    result = s.split(": ")
    if len(result)==2:
        return True
    return False
def getDataFromLine(line):
    split_line = line.split(" - ")
    date, time = split_line[0].split(", ")
    message = " ".join(split_line[1:])
    if is_author(message):
        author, message = message.split(": ", maxsplit=1)
    else:
        author =None
    return date, time, author, message
whatsapp_file = "WhatsApp-Chat-with-John.txt"
data = []
with open(whatsapp_file, encoding='utf-8') as fd:
    date, time, author = None,None, None
    msg_buffer = []
    while True:
        line = fd.readline().strip()
        if is_date_time(line):
            if(len(msg_buffer)>0):
                data.append([date, time, author, " ".join(msg_buffer)])
            msg_buffer.clear()
            date, time, author, message = getDataFromLine(line)
            msg_buffer.append(message)
        else:
            msg_buffer.append(line)
df = pd.DataFrame(data, columns=["date","time","author","message"])

            
            

StarcoderdataJupyterScriptsDedupFiltered