remove direct messages
authorymh <ymh.work@gmail.com>
Wed, 13 Jan 2021 10:40:41 +0100
changeset 1541 61423ca4e0af
parent 1540 0e5803a7babc
child 1542 82b5f22448f6
remove direct messages
script/utils/export_chat_zoom.py
--- a/script/utils/export_chat_zoom.py	Tue Jan 12 17:30:44 2021 +0100
+++ b/script/utils/export_chat_zoom.py	Wed Jan 13 10:40:41 2021 +0100
@@ -195,6 +195,7 @@
 
 CHAT_REGEXP = re.compile(r"^(?P<created_at>\d{2}:\d{2}:\d{2})\t\sFrom\s{2}(?P<user>.+?)\s:\s(?P<text>.*)$", re.DOTALL)
 CHAT_LINE_REGEXP = re.compile(r"^\d{2}:\d{2}:\d{2}\t\sFrom\s{2}.+?\s:")
+CHAT_DM_REGEXP = re.compile(r"\(Direct Message\)", re.IGNORECASE)
 
 def parse_chat_line(chat_id, chat_line):
     if (m := CHAT_REGEXP.match(chat_line)) is not None:
@@ -211,12 +212,12 @@
     with open(chat_file_path, "r") as chat_file:
         for chat_line in chat_file:
             if CHAT_LINE_REGEXP.match(chat_line) is not None:
-                if current_line:
+                if current_line and CHAT_DM_REGEXP.search(current_line) is None:
                     chat_content.append(current_line)
                 current_line = chat_line
             else:
                 current_line = current_line + "\n" + chat_line
-    if current_line:
+    if current_line and CHAT_DM_REGEXP.search(current_line) is None:
         chat_content.append(current_line)
     return chat_content
 
@@ -476,6 +477,8 @@
             cht_ts = parse_date(cht_ts_dt, item_tz, default_date.replace(tzinfo=item_tz))
             if start_date is None:
                 start_date = cht_ts
+            if cht_ts < start_date or cht_ts > end_date:
+                continue
             cht_ts_rel = cht_ts-start_date
             cht_ts_rel_milli = int(round(cht_ts_rel.total_seconds() * 1000))
             if deltas: