-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopening_title.py
More file actions
53 lines (40 loc) · 1.48 KB
/
opening_title.py
File metadata and controls
53 lines (40 loc) · 1.48 KB
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
41
42
43
44
45
46
47
48
import wikipedia
import json
import csv
import time
from wikipedia.exceptions import PageError
from wikipedia.wikipedia import suggest
openings_file=open('openings.txt', 'w')
dict={}
# opening the CSV file
with open('data/organized/lichess_data_organized_medium.csv', "r")as file:
# reading the CSV file
reader=csv.DictReader(file)
# displaying the contents of the CSV file
for row in reader:
flag = 0
original_name=row['Opening']
row['Opening']=row['Opening'].replace(':','')
if(row['Opening'].find(";")!=-1):
row['Opening']=row['Opening'][:row['Opening'].rfind(";")]
print("----------"+row['Opening']+"----------")
time.sleep(1)
while(1):
try:
suggestion=wikipedia.page(row['Opening']).title
except PageError:
row['Opening']=row['Opening'][:row['Opening'].rfind(" ")]
if(row['Opening'].find(suggestion[:4])!=-1):
break
print(suggestion)
print("\n")
summary=wikipedia.summary(suggestion)
""" except PageError:
row['Opening']=row['Opening'][:row['Opening'].rfind(" ")]
"""
print(summary)
print("\n")
openings_file=open('openings.txt', 'a')
struct={"original name": original_name, "wiki_name": suggestion}
openings_file.write(json.dumps(struct))
openings_file.close()