Created
December 13, 2012 21:48
-
-
Save alexstorer/4280259 to your computer and use it in GitHub Desktop.
Parse highlighter files.
This file contains hidden or 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
| import re | |
| fname = 'inp.txt' | |
| colors = ['red','green','blue','orange','yellow'] | |
| colorheaders = ['red is for X','green is for y','blue','orange','yellow'] | |
| colorstrings = [] | |
| for c in colors: | |
| colorstrings.append('') | |
| outname = 'sorted.txt' | |
| f = open(fname) | |
| fout = open(outname,'w') | |
| inColor = False | |
| for line in f: | |
| m = re.search('highlighted \| ([a-z]+)',line) | |
| # Are we at a highlighter line? | |
| if m: | |
| cname = m.groups(0)[0] | |
| else: | |
| cname = None | |
| if cname in colors: | |
| fred.write(line) | |
| inColor = True | |
| thisColor = colors.index(cname) | |
| colorstrings[thisColor] += (line + '\n') | |
| elif re.search('={80}',line) and inColor: | |
| colorstrings[thisColor] += (line + '\n') | |
| inColor = False | |
| elif inColor: | |
| colorstrings[thisColor] += (line + '\n') | |
| else: | |
| continue | |
| for (h,s) in zip(colorheaders,colorstrings): | |
| fout.write(">>>>>>>>>>>>>>>>>>>>>>>>\n") | |
| fout.write(h.upper()+'\n') | |
| fout.write("Lines:"+ str(s.count('\n'))) | |
| fout.write('\n') | |
| fout.write("<<<<<<<<<<<<<<<<<<<<<<<<\n") | |
| fout.write(s) | |
| f.close() | |
| fout.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment