-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodify_pgn.py
More file actions
30 lines (24 loc) · 944 Bytes
/
modify_pgn.py
File metadata and controls
30 lines (24 loc) · 944 Bytes
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
def is_drawn_game(block):
return block.strip().endswith("1/2-1/2")
def extract_blocks(file_path):
with open(file_path, 'r') as file:
lines = file.read().splitlines()
blocks = []
current_block = []
for line in lines:
if line.strip() == "":
blocks.append("\n".join(current_block))
current_block = []
else:
current_block.append(line)
return blocks
def remove_drawn_games(file_path, output_file_path):
blocks = extract_blocks(file_path)
with open(output_file_path, 'w') as output_file:
for i in range(len(blocks)):
if not is_drawn_game(blocks[i]):
output_file.write(blocks[i] + "\n\n")
input_file_path = "Anand_NoDraws.pgn"
output_file_path = "Anand_NoDraws_NoDraws.pgn"
remove_drawn_games(input_file_path, output_file_path)
print("Blocks with drawn games removed. New file saved as 'Anand_NoDraws_NoDraws.pgn'.")