Created
February 7, 2016 02:04
-
-
Save Karunamon/81384a98f162e554bdeb to your computer and use it in GitHub Desktop.
Python script for cleaning mIRC color codes from IRC logs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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