script/utils/export_chat_zoom.py
changeset 1541 61423ca4e0af
parent 1538 4e5ee8e79e7f
child 1542 82b5f22448f6
equal deleted inserted replaced
1540:0e5803a7babc 1541:61423ca4e0af
   193         }
   193         }
   194         return int(round(datetime.timedelta(**time_params).total_seconds()*1000))
   194         return int(round(datetime.timedelta(**time_params).total_seconds()*1000))
   195 
   195 
   196 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)
   196 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)
   197 CHAT_LINE_REGEXP = re.compile(r"^\d{2}:\d{2}:\d{2}\t\sFrom\s{2}.+?\s:")
   197 CHAT_LINE_REGEXP = re.compile(r"^\d{2}:\d{2}:\d{2}\t\sFrom\s{2}.+?\s:")
       
   198 CHAT_DM_REGEXP = re.compile(r"\(Direct Message\)", re.IGNORECASE)
   198 
   199 
   199 def parse_chat_line(chat_id, chat_line):
   200 def parse_chat_line(chat_id, chat_line):
   200     if (m := CHAT_REGEXP.match(chat_line)) is not None:
   201     if (m := CHAT_REGEXP.match(chat_line)) is not None:
   201         res = {k: v.replace('\r','\n') if k == 'text' else v for k,v in m.groupdict().items()}
   202         res = {k: v.replace('\r','\n') if k == 'text' else v for k,v in m.groupdict().items()}
   202         res['id'] = chat_id
   203         res['id'] = chat_id
   209     current_line = ""
   210     current_line = ""
   210     chat_content = []
   211     chat_content = []
   211     with open(chat_file_path, "r") as chat_file:
   212     with open(chat_file_path, "r") as chat_file:
   212         for chat_line in chat_file:
   213         for chat_line in chat_file:
   213             if CHAT_LINE_REGEXP.match(chat_line) is not None:
   214             if CHAT_LINE_REGEXP.match(chat_line) is not None:
   214                 if current_line:
   215                 if current_line and CHAT_DM_REGEXP.search(current_line) is None:
   215                     chat_content.append(current_line)
   216                     chat_content.append(current_line)
   216                 current_line = chat_line
   217                 current_line = chat_line
   217             else:
   218             else:
   218                 current_line = current_line + "\n" + chat_line
   219                 current_line = current_line + "\n" + chat_line
   219     if current_line:
   220     if current_line and CHAT_DM_REGEXP.search(current_line) is None:
   220         chat_content.append(current_line)
   221         chat_content.append(current_line)
   221     return chat_content
   222     return chat_content
   222 
   223 
   223 
   224 
   224 if __name__ == "__main__" :
   225 if __name__ == "__main__" :
   474             cht_ts_dt = cht['created_at']
   475             cht_ts_dt = cht['created_at']
   475             default_date = start_date or datetime.now()
   476             default_date = start_date or datetime.now()
   476             cht_ts = parse_date(cht_ts_dt, item_tz, default_date.replace(tzinfo=item_tz))
   477             cht_ts = parse_date(cht_ts_dt, item_tz, default_date.replace(tzinfo=item_tz))
   477             if start_date is None:
   478             if start_date is None:
   478                 start_date = cht_ts
   479                 start_date = cht_ts
       
   480             if cht_ts < start_date or cht_ts > end_date:
       
   481                 continue
   479             cht_ts_rel = cht_ts-start_date
   482             cht_ts_rel = cht_ts-start_date
   480             cht_ts_rel_milli = int(round(cht_ts_rel.total_seconds() * 1000))
   483             cht_ts_rel_milli = int(round(cht_ts_rel.total_seconds() * 1000))
   481             if deltas:
   484             if deltas:
   482                 d = find_delta(deltas, cht_ts_rel_milli)
   485                 d = find_delta(deltas, cht_ts_rel_milli)
   483                 if d[1] < 0:
   486                 if d[1] < 0: