File size: 1,278 Bytes
726c702
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d86eeec
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
import re
import json

# Funci贸n para convertir archivo de WhatsApp a JSONL
def whatsapp_txt_a_jsonl(archivo_txt, archivo_jsonl):
    # Expresi贸n regular para capturar el timestamp, sender y mensaje
    patron = r'\[(.*?)\] (.*?): (.*)'

    # Abre el archivo de WhatsApp
    with open(archivo_txt, 'r', encoding='utf-8') as txt_file:
        with open(archivo_jsonl, 'w', encoding='utf-8') as jsonl_file:
            for linea in txt_file:
                # Usar expresi贸n regular para extraer los datos
                match = re.match(patron, linea)
                if match:
                    timestamp, sender, message = match.groups()
                    # Crear un diccionario con los datos
                    json_obj = {
                        "timestamp": timestamp,
                        "sender": sender,
                        "message": message
                    }
                    # Escribir el objeto en formato JSONL (una l铆nea por cada mensaje)
                    jsonl_file.write(json.dumps(json_obj, ensure_ascii=False) + '\n')

    print(f"Archivo {archivo_jsonl} creado exitosamente.")

# Convierte el archivo .txt a .jsonl
whatsapp_txt_a_jsonl('/Users/acavadondeteneselarchivo/_chat.txt', '/Users/acadondevaconversion/Chat/output.jsonl')