Python Forum
Trying to parse and work with the WhatsApp export of chats
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying to parse and work with the WhatsApp export of chats
#2
My goto here would be to use a regular expression to match lines with the formatting you want. You can ignore, store, or otherwise flag the lines that don't match.

import re

text_in = """9/5/21, 8:07 PM - Me: Lol romantic comedy
https://music.youtube.com/
2006 present
9/5/21, 8:38 PM - Friend: Yup
"""

datetime_rx = re.compile(r"(\d\d?/\d\d?/\d\d, \d\d?:\d\d [AP]M) - (.*)")
for line in text_in.splitlines():
    match = datetime_rx.match(line)
    if match:
        print(f"Found timestamp: {match.groups()[0]}, Contents: {match.groups()[1]}")
    else:
        print(f"no timestamp: {line}")
cubangt likes this post
Reply


Messages In This Thread
RE: Trying to parse and work with the WhatsApp export of chats - by bowlofred - Dec-15-2021, 11:35 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I am sending messages using Python to Telegram, but I need to use WhatsApp for it Hendrikb 0 375 Apr-29-2025, 09:38 AM
Last Post: Hendrikb
  Eliminate entering QR - Whatsapp web automated by selenium akanowhere 1 4,203 Jan-21-2024, 01:12 PM
Last Post: owalahtole
  Sending Whatsapp Message in the text file ebincharles869 9 6,543 Jun-21-2022, 04:26 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020