Main.py 1.1 KB

123456789101112131415161718192021222324252627282930
  1. import re
  2. def Start(First_Date, Second_Date, First_Name, Second_Name):
  3. First = re.compile(f'^{First_Date} .* {First_Name}$') # 个人聊天
  4. Second = re.compile(f'^{Second_Date} .* {Second_Name}$') # 群内匹配
  5. First_Count = 0 # 个人聊天条数
  6. Second_Cound = 0 # 群内条数
  7. with open(First_Dic, 'r', encoding='UTF-8') as f:
  8. for i in f:
  9. p = re.match(First, i)
  10. if not p == None:
  11. First_Count += 1
  12. with open(Second_Dic, 'r', encoding='UTF-8') as f:
  13. for i in f:
  14. p = re.match(Second, i)
  15. if not p == None:
  16. Second_Cound += 1
  17. return First_Count, Second_Cound
  18. First_Date = r'2020-02-23'#第一聊天记录:检查的日期
  19. Second_Date = r'2020-02-23'#第二聊天记录:检查的日期
  20. First_Name = r'xxx'#群内昵称(备注昵称)
  21. Second_Name = r'yyy'#群内昵称(备注昵称)
  22. First_Dic = r'xxxx.txt'#聊天记录的位置
  23. Second_Dic = r'xxxx.txt'#聊天记录的位置
  24. First_Count,Second_Cound = Start(First_Date,Second_Date,First_Name,Second_Name)
  25. print(f'聊天条数1:{First_Count}')
  26. print(f'聊天条数2:{Second_Cound}')