Skip to content

Instantly share code, notes, and snippets.

@xgfs
Created December 24, 2016 11:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xgfs/9c6fc4f5c4d376750fe86a7437c60049 to your computer and use it in GitHub Desktop.
Save xgfs/9c6fc4f5c4d376750fe86a7437c60049 to your computer and use it in GitHub Desktop.
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