Created
December 24, 2016 11:13
-
-
Save xgfs/9c6fc4f5c4d376750fe86a7437c60049 to your computer and use it in GitHub Desktop.
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
def line_to_pgn(line, white, black, result): | |
return '[White "{}"]\n[Black "{}"] \n[Result "{}"]\n\n{}*\n\n'.format(white, black, result, line) | |
with open('games-all.pgn', 'w') as outf: | |
first_line = True | |
with open('white-moves.txt', 'r') as inf: | |
for line in inf: | |
if first_line: | |
first_line = False | |
continue | |
line = line.replace('{100%}', '') | |
outf.write(line_to_pgn(line[line.index(':')+2:-1], 'SF', 'other', '1/2-1/2')) | |
first_line = True | |
with open('black-moves.txt', 'r') as inf: | |
for line in inf: | |
if first_line: | |
first_line = False | |
continue | |
line = line.replace('{100%}', '') | |
outf.write(line_to_pgn(line[line.index(':')+2:-1], 'other', 'SF', '1/2-1/2')) | |
with open('games-white.pgn', 'w') as outf: | |
first_line = True | |
with open('white-moves.txt', 'r') as inf: | |
for line in inf: | |
if first_line: | |
first_line = False | |
continue | |
line = line.replace('{100%}', '') | |
outf.write(line_to_pgn(line[line.index(':')+2:-1], 'SF', 'other', '1-0')) | |
with open('games-black.pgn', 'w') as outf: | |
first_line = True | |
with open('black-moves.txt', 'r') as inf: | |
for line in inf: | |
if first_line: | |
first_line = False | |
continue | |
line = line.replace('{100%}', '') | |
outf.write(line_to_pgn(line[line.index(':')+2:-1], 'other', 'SF', '0-1')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment