Browse Source

Initial commit

master
JustAnotherArchivist 3 years ago
commit
80a0bfa2c4
1 changed files with 44 additions and 0 deletions
  1. +44
    -0
      efnet-irclogger-convert.py

+ 44
- 0
efnet-irclogger-convert.py View File

@@ -0,0 +1,44 @@
import datetime
import sys


assert len(sys.argv) == 2, 'Arg: filename'
filename = sys.argv[1]

date = filename[:10]

with open(filename, 'r') as fp:
for line in fp:
origLine = line
if not (line[0] == '[' and line[3] == ':' and line[6:8] == '] ' and line[-1] == '\n'):
print(f'MALFORMED LINE: {line!r}', file = sys.stderr)
continue
time = line[1:6]
line = line[8:-1]
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()
if line.startswith('<'): #PRIVMSG
print(f'{ts} PRIVMSG {line}')
elif line.startswith('* '): #ACTION
print(f'{ts} ACTION {line[2:]}')
elif line.startswith('*** '):
words = line.split(' ')[1:]
if words[1:3] == ['has', 'joined']: # JOIN
print(f'{ts} JOIN {words[0]} joins')
elif words[1:3] == ['has', 'left']: # PART
print(f'{ts} PART {words[0]} leaves')
elif words[1:4] == ['has', 'quit', 'IRC']: # QUIT
print(f'{ts} QUIT {words[0]} quits [{" ".join(words[4:])[1:-1]}]')
elif words[1:4] == ['was', 'kicked', 'by']: # KICK
print(f'{ts} KICK {words[0]} is kicked by {words[4]} [{" ".join(words[5:])[1:-1]}]')
elif words[1:3] == ['sets', 'mode:']: # MODE
print(f'{ts} MODE {line[4:]}')
elif words[1:4] == ['changes', 'topic', 'to:']: # TOPIC
print(f'{ts} TOPIC {words[0]} sets the topic to: {" ".join(words[5:])}')
elif words[1:5] == ['is', 'now', 'known', 'as']: # NICK
print(f'{ts} NICK {line[4:]}')
elif words[1:3] == ['starts', 'logging']: # Silently ignore (there's already a JOIN)
pass
else:
print(f'MALFORMED LINE: {origLine!r}', file = sys.stderr)
else:
print(f'MALFORMED LINE: {origLine!r}', file = sys.stderr)

Loading…
Cancel
Save