| import re |
| import json |
|
|
| |
| def whatsapp_txt_a_jsonl(archivo_txt, archivo_jsonl): |
| |
| patron = r'\[(.*?)\] (.*?): (.*)' |
|
|
| |
| 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: |
| |
| match = re.match(patron, linea) |
| if match: |
| timestamp, sender, message = match.groups() |
| |
| json_obj = { |
| "timestamp": timestamp, |
| "sender": sender, |
| "message": message |
| } |
| |
| jsonl_file.write(json.dumps(json_obj, ensure_ascii=False) + '\n') |
|
|
| print(f"Archivo {archivo_jsonl} creado exitosamente.") |
|
|
| |
| whatsapp_txt_a_jsonl('/Users/acavadondeteneselarchivo/_chat.txt', '/Users/acadondevaconversion/Chat/output.jsonl') |
|
|