Repository: joweich/chat-miner

Issue:
ValueError: not enough values to unpack (expected 2, got 1)
Seeing the following error while using the WhatsApp parser:

```
22.04.2023 12:04:32 INFO     
            Depending on the platform, the message format in chat logs might not be
            standardized accross devices/versions/localization and might change over
            time. Please report issues including your message format via GitHub.
            
22.04.2023 12:04:32 INFO     Initialized parser.
22.04.2023 12:04:32 INFO     Starting reading raw messages...
22.04.2023 12:04:33 INFO     Inferred date format: month/day/year
22.04.2023 12:04:33 INFO     Finished reading 39999 raw messages.
22.04.2023 12:04:33 INFO     Starting parsing raw messages...
  0%|                                                                                        | 1/39999 [00:00<?, ?it/s]

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[6], line 4
      1 from chatminer.chatparsers import WhatsAppParser
      3 parser = WhatsAppParser("WhatsApp-Chat-Sarmad.txt")
----> 4 parser.parse_file()
      5 df = parser.parsed_messages.get_df()

File E:\Projects\whatsapp-chat-miner\whatsapp-analysis\lib\site-packages\chatminer\chatparsers.py:74, in Parser.parse_file(self)
     71 self._logger.info("Finished reading %i raw messages.", len(self._raw_messages))
     73 self._logger.info("Starting parsing raw messages...")
---> 74 self._parse_raw_messages()
     75 self._logger.info("Finished parsing raw messages.")

File E:\Projects\whatsapp-chat-miner\whatsapp-analysis\lib\site-packages\chatminer\chatparsers.py:84, in Parser._parse_raw_messages(self)
     82 with logging_redirect_tqdm():
     83     for raw_mess in tqdm(self._raw_messages):
---> 84         parsed_mess = self._parse_message(raw_mess)
     85         if parsed_mess:
     86             self.parsed_messages.append(parsed_mess)

File E:\Projects\whatsapp-chat-miner\whatsapp-analysis\lib\site-packages\chatminer\chatparsers.py:168, in WhatsAppParser._parse_message(self, mess)
    163 time = datetimeparser.parse(
    164     datestr, dayfirst=self._datefmt.is_dayfirst, fuzzy=True
    165 )
    167 if ":" in author_and_body:
--> 168     author, body = [x.strip() for x in author_and_body.split(": ", 1)]
    169 else:
    170     author = "System"

ValueError: not enough values to unpack (expected 2, got 1)
```

Might be because of a format that is not being covered.

Comments:

Patch:
diff --git a/chatminer/chatparsers.py b/chatminer/chatparsers.py
index d402c2a..d1d2890 100644
--- a/chatminer/chatparsers.py
+++ b/chatminer/chatparsers.py
@@ -164,8 +164,11 @@ class WhatsAppParser(Parser):
             datestr, dayfirst=self._datefmt.is_dayfirst, fuzzy=True
         )
 
-        if ":" in author_and_body:
+        if ": " in author_and_body:
             author, body = [x.strip() for x in author_and_body.split(": ", 1)]
+        elif ":." in author_and_body:
+            author = [x.strip() for x in author_and_body.split(":.", 1)][0]
+            body = "<Disappearing Message>"
         else:
             author = "System"
             body = author_and_body.strip()


Test patch:
diff --git a/test/test_whatsapp.py b/test/test_whatsapp.py
index f95dc1f..5459ef5 100644
--- a/test/test_whatsapp.py
+++ b/test/test_whatsapp.py
@@ -13,7 +13,7 @@ def assert_equal_from_file(file):
         parse_dates=["timestamp"],
         infer_datetime_format=True,
     )
-    assert_frame_equal(df_test, df_res)
+    assert_frame_equal(df_test, df_res, check_dtype=False)
 
 
 def test_dateformat1():
diff --git a/test/whatsapp/test_dateformat1.txt b/test/whatsapp/test_dateformat1.txt
index 61f666d..74c85a4 100644
--- a/test/whatsapp/test_dateformat1.txt
+++ b/test/whatsapp/test_dateformat1.txt
@@ -1,3 +1,4 @@
+12/24/19, 11:23 - John Doe:.
 12/24/19, 11:23 - John Doe: Lorem ipsum dolor sit amet.
 12/24/19, 11:23 - John Doe: Lorem ipsum : dolor sit amet.
 12/26/19, 11:55 - John-John Doe: Lorem ipsum : dolor sit amet.
diff --git a/test/whatsapp/test_dateformat1_target.csv b/test/whatsapp/test_dateformat1_target.csv
index fa1477a..345a5b6 100644
--- a/test/whatsapp/test_dateformat1_target.csv
+++ b/test/whatsapp/test_dateformat1_target.csv
@@ -8,3 +8,4 @@ timestamp,author,message,weekday,hour,words,letters
 2019-12-26 11:55:00,John-John Doe,Lorem ipsum : dolor sit amet.,Thursday,11,6,29
 2019-12-24 11:23:00,John Doe,Lorem ipsum : dolor sit amet.,Tuesday,11,6,29
 2019-12-24 11:23:00,John Doe,Lorem ipsum dolor sit amet.,Tuesday,11,5,27
+2019-12-24 11:23:00,John Doe,<Disappearing Message>,Tuesday,11,2,22