Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Python script for cleaning mIRC color codes from IRC logs
#!/usr/bin/env python
"""mIRC Color Code Stripper
Removes mIRC color codes from provided files.
Usage:
stripMirc.py <filename> [OUTPUT]
If OUTPUT is not specified, filename will be the original filename, with a _FIXED extension.
"""
import re
import sys
from docopt import docopt
if __name__ == "__main__":
args = docopt(__doc__, version='stripMirc v1.0')
outfile = args['OUTPUT'] if args['OUTPUT'] else args['<filename>'] + '_FIXED'
#Thanks to ZeroKnight
#http://stackoverflow.com/questions/29247659/how-to-remove-all-irc-colour-codes-from-string
rex = re.compile('[\x02\x0F\x16\x1D\x1F]|\x03(\d{,2}(,\d{,2})?)?')
i_file = open(args['<filename>'], 'r')
o_file = open(outfile, 'a')
ctr = 0
for line in i_file:
ctr+=1
o_file.write(rex.sub('', line))
print("%s: processed" % args['<filename>'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment