-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathchess.py
More file actions
36 lines (32 loc) · 765 Bytes
/
chess.py
File metadata and controls
36 lines (32 loc) · 765 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
31
32
33
34
35
36
import pgn
import re
import json
from openpyxl import Workbook
wb = Workbook()
ws = wb.active
temp_arr = []
arr = []
def Remove(duplicate,dup):
final_list = []
for num in duplicate:
if num != dup:
final_list.append(num)
return final_list
def hello(temp_arr):
for word in temp_arr:
arr=word.split(' ')
arr=Remove(arr,'')
arr=Remove(arr,arr[(len(arr)-1)])
if(arr != []):
if(len(arr)==2):
ws.append([arr[0],arr[1]])
if(len(arr)==3):
ws.append([arr[0],arr[1],arr[2]])
pgn_text = open('data.pgn').read()
s = pgn_text
s=re.sub(r'\[(.*?)\]', '', s)
s=s.replace('[]','')
s=s.replace('\n', " ")
temp_arr = s.split('.')
hello(temp_arr[1500000:2000000])
wb.save("chess_moves6.xlsx")