-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnumber_games.py
executable file
·40 lines (33 loc) · 967 Bytes
/
number_games.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python
import sys
import chess
import chess.pgn
import os
pgn_fd = open(sys.argv[1], 'r')
game_num = 50001
for line in pgn_fd:
line = line.strip()
if line.startswith('[Event'):
print '[Event "%i"]' % game_num
game_num = game_num + 1
print line.replace('Event', 'RealEvent')
else:
print line
if False:
game_num = 50001
game = chess.pgn.read_game(pgn_fd)
while game is not None:
game.headers['RealEvent'] = game.headers['Event']
game.headers['Event'] = game_num
exporter = chess.pgn.StringExporter()
game.export(exporter, headers=True, variations=False, comments=False)
sys.stdout.write(str(exporter))
sys.stdout.write('\n\n')
sys.stdout.flush()
game_num = game_num + 1
game = None
while game is None:
try:
game = chess.pgn.read_game(pgn_fd)
except:
pass