Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. import re
  2. import datetime
  3.  
  4. line_start_pattern = r"^(\[)(.*?)(\])(\s)(.*?)(:)(.*)$"
  5.  
  6.  
  7. all_txt = open('chat.txt') # exported input file
  8.  
  9. out_text = open('chat-cleared.txt', 'w') # cleaned up file
  10.  
  11. for i, line in enumerate(all_txt):
  12. match = re.match(line_start_pattern, line)
  13. if match:
  14. # print(line)
  15. matches = match.groups()
  16. print(len(matches))
  17. if(len(matches) == 7):
  18. date = datetime.datetime.strptime(
  19. matches[1], '%d/%m/%y, %H:%M:%S').strftime("%Y-%m-%d %H:%M:%S")
  20. user = matches[4]
  21. out_text.write("\"{0}\", \"{1}\"\n".format(date, user))
  22.  
  23. out_text.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement