You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.7 KiB

  1. import datetime
  2. import sys
  3. assert len(sys.argv) == 2, 'Arg: filename'
  4. filename = sys.argv[1]
  5. date = filename[:10]
  6. with open(filename, 'r') as fp:
  7. for line in fp:
  8. origLine = line
  9. if not (line[0] == '[' and line[3] == ':' and line[6:8] == '] ' and line[-1] == '\n'):
  10. print(f'MALFORMED LINE: {line!r}', file = sys.stderr)
  11. continue
  12. time = line[1:6]
  13. line = line[8:-1]
  14. ts = datetime.datetime(int(date[:4]), int(date[5:7]), int(date[8:]), int(time[:2]), int(time[3:]), 0).replace(tzinfo = datetime.timezone.utc).timestamp()
  15. if line.startswith('<'): #PRIVMSG
  16. print(f'{ts} PRIVMSG {line}')
  17. elif line.startswith('* '): #ACTION
  18. print(f'{ts} ACTION {line[2:]}')
  19. elif line.startswith('*** '):
  20. words = line.split(' ')[1:]
  21. if words[1:3] == ['has', 'joined']: # JOIN
  22. print(f'{ts} JOIN {words[0]} joins')
  23. elif words[1:3] == ['has', 'left']: # PART
  24. print(f'{ts} PART {words[0]} leaves')
  25. elif words[1:4] == ['has', 'quit', 'IRC']: # QUIT
  26. print(f'{ts} QUIT {words[0]} quits [{" ".join(words[4:])[1:-1]}]')
  27. elif words[1:4] == ['was', 'kicked', 'by']: # KICK
  28. print(f'{ts} KICK {words[0]} is kicked by {words[4]} [{" ".join(words[5:])[1:-1]}]')
  29. elif words[1:3] == ['sets', 'mode:']: # MODE
  30. print(f'{ts} MODE {line[4:]}')
  31. elif words[1:4] == ['changes', 'topic', 'to:']: # TOPIC
  32. print(f'{ts} TOPIC {words[0]} sets the topic to: {" ".join(words[5:])}')
  33. elif words[1:5] == ['is', 'now', 'known', 'as']: # NICK
  34. print(f'{ts} NICK {line[4:]}')
  35. elif words[1:3] == ['starts', 'logging']: # Silently ignore (there's already a JOIN)
  36. pass
  37. else:
  38. print(f'MALFORMED LINE: {origLine!r}', file = sys.stderr)
  39. else:
  40. print(f'MALFORMED LINE: {origLine!r}', file = sys.stderr)