Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

116 Zeilen
8.1 KiB

  1. import datetime
  2. import sys
  3. assert len(sys.argv) == 2, 'Arg: filename'
  4. filename = sys.argv[1]
  5. date = filename.rsplit('/', 1)[-1][:10]
  6. with open(filename, 'rb') as fp:
  7. for line in fp:
  8. if line == b'\n':
  9. continue
  10. origLine = line
  11. if not (line[0:1] == b'[' and line[3:4] == b':' and line[6:8] == b'] ' and line[-1:] == b'\n'):
  12. print(f'GROSSLY MALFORMED LINE: {line!r}', file = sys.stderr)
  13. continue
  14. time = line[1:6].decode('ascii')
  15. line = line[8:-1]
  16. 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()
  17. if line.startswith(b'<'): # PRIVMSG
  18. sys.stdout.buffer.write(f'{ts} PRIVMSG '.encode('ascii') + line + b'\n')
  19. elif line.startswith(b'* '): # ACTION
  20. sys.stdout.buffer.write(f'{ts} ACTION '.encode('ascii') + line[2:] + b'\n')
  21. elif line.startswith(b'*** '):
  22. words = line.split(b' ')[1:]
  23. # JOIN
  24. if words[1:3] == [b'has', b'joined']:
  25. if b'!' in words[0]: # irssi format
  26. words[0] = words[0].split(b'!', 1)[0]
  27. sys.stdout.buffer.write(f'{ts} JOIN '.encode('ascii') + words[0] + b' joins' + b'\n')
  28. elif words[2:4] == [b'has', b'joined'] and words[1][0:1] == b'(' and words[1][-1:] == b')':
  29. sys.stdout.buffer.write(f'{ts} JOIN '.encode('ascii') + words[0] + b' joins' + b'\n')
  30. elif words[2:] == [b'joined', b'the', b'channel']: # (newsgrabber 2015-12-21)
  31. sys.stdout.buffer.write(f'{ts} JOIN '.encode('ascii') + words[0] + b' joins' + b'\n')
  32. elif words[0] == b'Joins:':
  33. sys.stdout.buffer.write(f'{ts} JOIN '.encode('ascii') + words[1] + b' joins' + b'\n')
  34. # PART
  35. elif words[1:3] == [b'has', b'left'] and ((b'!' in words[0] and words[4][0:1] == b'[' and words[-1][-1:] == b']') or b'!' not in words[0]):
  36. if b'!' in words[0]: # irssi format
  37. words[0] = words[0].split(b'!', 1)[0]
  38. words[4] = words[4][1:]
  39. words[-1] = words[-1][:-1]
  40. words = words[0:3] + words[4:]
  41. reason = (b' [' + b' '.join(words[3:]) + b']') if len(words) > 4 or words[3] != b'' else b''
  42. sys.stdout.buffer.write(f'{ts} PART '.encode('ascii') + words[0] + b' leaves' + reason + b'\n')
  43. elif words[2:4] == [b'has', b'left'] and words[1][0:1] == b'(' and words[1][-1:] == b')' and len(words) >= 5:
  44. reason = (b' [' + b' '.join(words[5:])[1:-1] + b']') if len(words) > 6 or (len(words) == 6 and words[5] != b'()') else b''
  45. sys.stdout.buffer.write(f'{ts} PART '.encode('ascii') + words[0] + b' leaves' + reason + b'\n')
  46. elif words[2:] == [b'left', b'the', b'channel']: # (projectnewsletter 2015-04-01)
  47. sys.stdout.buffer.write(f'{ts} PART '.encode('ascii') + words[0] + b' leaves' + b'\n')
  48. elif words[0] == b'Parts:' and words[3][0:1] == b'(' and words[-1][-1:] == b')':
  49. reason = (b' [' + b' '.join(words[3:])[1:-1] + b']') if len(words) > 4 or words[3] != b'()' else b''
  50. sys.stdout.buffer.write(f'{ts} PART '.encode('ascii') + words[1] + b' leaves' + reason + b'\n')
  51. # QUIT
  52. elif words[1:4] == [b'has', b'quit', b'IRC'] and words[4][0:1] == b'(' and words[-1][-1:] == b')':
  53. reason = (b' [' + b' '.join(words[4:])[1:-1] + b']') if len(words) > 5 or words[4] != b'()' else b''
  54. sys.stdout.buffer.write(f'{ts} QUIT '.encode('ascii') + words[0] + b' quits' + reason + b'\n')
  55. elif words[1:3] == [b'has', b'quit'] and b'!' in words[0] and words[3][0:1] == b'[' and words[-1][-1:] == b']':
  56. words[0] = words[0].split(b'!', 1)[0]
  57. reason = (b' [' + b' '.join(words[3:])[1:-1] + b']') if len(words) > 4 or words[3] != b'[]' else b''
  58. sys.stdout.buffer.write(f'{ts} QUIT '.encode('ascii') + words[0] + b' quits' + reason + b'\n')
  59. elif words[1:3] == [b'has', b'quit'] and words[3][0:1] == b'(' and words[-1][-1:] == b')': # (archivebot 2015-10 and 2016-02/03)
  60. reason = (b' [' + b' '.join(words[3:])[1:-1] + b']') if len(words) > 4 or words[3] != b'[]' else b''
  61. sys.stdout.buffer.write(f'{ts} QUIT '.encode('ascii') + words[0] + b' quits' + reason + b'\n')
  62. elif words[2:4] == [b'left', b'IRC'] and words[1][0:1] == b'(' and words[1][-1:] == b')' and (len(words) == 4 or (words[4][0:1] == b'(' and words[-1][-1:] == b')')): # (projectnewsletter 2015-03-27, 2015-03-23)
  63. reason = (b' [' + b' '.join(words[4:])[1:-1] + b']') if len(words) > 5 or (len(words) == 5 and words[4] != b'()') else b''
  64. sys.stdout.buffer.write(f'{ts} QUIT '.encode('ascii') + words[0] + b' quits' + reason + b'\n')
  65. elif words[0] == b'Quits:' and words[3][0:1] == b'(' and words[-1][-1:] == b')':
  66. reason = (b' [' + b' '.join(words[3:])[1:-1] + b']') if len(words) > 4 or words[3] != b'()' else b''
  67. sys.stdout.buffer.write(f'{ts} QUIT '.encode('ascii') + words[1] + b' quits' + reason + b'\n')
  68. # KICK
  69. elif words[1:4] == [b'was', b'kicked', b'by'] and words[5][0:1] == b'(' and words[-1][-1:] == b')':
  70. sys.stdout.buffer.write(f'{ts} KICK '.encode('ascii') + words[0] + b' is kicked by ' + words[4] + b' [' + b' '.join(words[5:])[1:-1] + b']' + b'\n')
  71. elif words[1:5] == [b'has', b'been', b'kicked', b'by'] and b'!' in words[5] and words[6][0:1] == b'[' and words[-1][-1:] == b']':
  72. sys.stdout.buffer.write(f'{ts} KICK '.encode('ascii') + words[0] + b' is kicked by ' + words[5].split(b'!', 1)[0] + b' [' + b' '.join(words[6:])[1:-1] + b']' + b'\n')
  73. # MODE
  74. elif words[1:3] == [b'sets', b'mode:'] or words[1:3] == [b'sets', b'mode']: # (newsgrabber 2015-12-20)
  75. words[2] = b'mode:'
  76. sys.stdout.buffer.write(f'{ts} MODE '.encode('ascii') + b' '.join(words) + b'\n')
  77. elif words[0].startswith(b'mode/') and words[1][0:1] == b'[' and words[-3][-1:] == b']':
  78. if b'!' in words[-1]: # Not always the case since the mode might be set by an IRCd after a netsplit
  79. words[-1] = words[-1].split(b'!', 1)[0]
  80. sys.stdout.buffer.write(f'{ts} MODE '.encode('ascii') + words[-1] + b' sets mode: ' + b' '.join(words[1:-2])[1:-1] + b'\n')
  81. elif words[1:6] == [b'gives', b'channel', b'operator', b'status', b'to'] and len(words) >= 7: # (archivebot 2016-02, internetarchive.bak 2015-03-02)
  82. sys.stdout.buffer.write(f'{ts} MODE '.encode('ascii') + words[0] + b' sets mode: +' + (b'o' * (len(words) - 6)) + b' ' + b' '.join(words[6:]) + b'\n')
  83. elif words[1:4] == [b'gives', b'voice', b'to'] and len(words) == 5:
  84. sys.stdout.buffer.write(f'{ts} MODE '.encode('ascii') + words[0] + b' sets mode: +v ' + words[-1] + b'\n')
  85. elif words[1:4] == [b'sets', b'ban', b'on'] and len(words) == 5:
  86. sys.stdout.buffer.write(f'{ts} MODE '.encode('ascii') + words[0] + b' sets mode: +b ' + words[-1] + b'\n')
  87. # TOPIC
  88. elif words[1:4] == [b'changes', b'topic', b'to:']:
  89. sys.stdout.buffer.write(f'{ts} TOPIC '.encode('ascii') + words[0] + b' sets the topic to: ' + b' '.join(words[4:]) + b'\n')
  90. elif words[1:4] == [b'changes', b'topic', b'to'] and words[4][0:1] == words[-1][-1:] == b"'":
  91. sys.stdout.buffer.write(f'{ts} TOPIC '.encode('ascii') + words[0] + b' sets the topic to: ' + b' '.join(words[4:])[1:-1] + b'\n')
  92. elif words[1:4] == [b'changed', b'topic', b'of']:
  93. sys.stdout.buffer.write(f'{ts} TOPIC '.encode('ascii') + words[0].split(b'!', 1)[0] + b' sets the topic to: ' + b' '.join(words[6:]) + b'\n')
  94. elif words[1:6] == [b'has', b'changed', b'the', b'topic', b'to:']:
  95. sys.stdout.buffer.write(f'{ts} TOPIC '.encode('ascii') + words[0] + b' sets the topic to: ' + b' '.join(words[6:]) + b'\n')
  96. elif words[1:5] == [b'changed', b'the', b'topic', b'to']:
  97. sys.stdout.buffer.write(f'{ts} TOPIC '.encode('ascii') + words[0] + b' sets the topic to: ' + b' '.join(words[5:]) + b'\n')
  98. # NICK
  99. elif words[1:5] == [b'is', b'now', b'known', b'as']:
  100. if b'!' in words[0]:
  101. words[0] = words[0].split(b'!', 1)[0]
  102. sys.stdout.buffer.write(f'{ts} NICK '.encode('ascii') + words[0] + b' is now known as ' + b' '.join(words[5:]) + b'\n')
  103. # Others
  104. elif words[1:3] == [b'starts', b'logging']: # Silently ignore, there's already a JOIN (irclogger 2020 etc.)
  105. pass
  106. else:
  107. print(f'MALFORMED LINE: {origLine!r}', file = sys.stderr)
  108. sys.stdout.buffer.write(f'{ts} OLDLOGS_UNCLASSIFIED '.encode('ascii') + line + b'\n')
  109. else:
  110. print(f'MALFORMED LINE: {origLine!r}', file = sys.stderr)
  111. sys.stdout.buffer.write(f'{ts} OLDLOGS_UNCLASSIFIED '.encode('ascii') + line + b'\n')