Skip to content

Commit 6b07813

Browse files
committed
Started contributing app
1 parent 5725f15 commit 6b07813

7 files changed

Lines changed: 136 additions & 2 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ pgns/*
55
stockfish/
66
stockfish.zip
77
__MAC*
8+
*cpython*

contribute/auto.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import os
2+
import sys
3+
import zipfile
4+
from pathlib import Path
5+
from subprocess import call
6+
from typing import *
7+
8+
import evalfen
9+
from getFile import downloadName, getAvailableNames
10+
from send import sendFile, sendNotification
11+
12+
STOCKFISH_DOWNLOAD = {
13+
"win32": "https://stockfishchess.org/files/stockfish-11-win.zip",
14+
"linux": "https://stockfishchess.org/files/stockfish-11-linux.zip",
15+
"linux32": "https://stockfishchess.org/files/stockfish-11-linux.zip",
16+
"darwin": "https://stockfishchess.org/files/stockfish-11-mac.zip"
17+
}
18+
19+
20+
def unzip(filepath, resultpath):
21+
with zipfile.ZipFile(filepath, 'r') as zip_ref:
22+
zip_ref.extractall(resultpath)
23+
24+
25+
def promptNames(names: List[str]) -> str:
26+
for i, name in enumerate(names):
27+
print(i, name, sep='\t')
28+
uin = int(input("Which number? "))
29+
return names[uin]
30+
31+
32+
def promptDownload() -> bool:
33+
uin = input("Do you need to download any other dataset?(y)es/(n)o ")
34+
return 'y' in uin
35+
36+
37+
def downloadStockfish() -> None:
38+
link = STOCKFISH_DOWNLOAD[sys.platform]
39+
call(["curl", "-o", "stockfish.zip", link])
40+
unzip("stockfish.zip", "stockfish/")
41+
42+
43+
def findStockfish() -> Path:
44+
pass
45+
46+
47+
def promptStockfish() -> Path:
48+
uin = input("Do you have stockfish in your current directory?(y)es/(n)o ")
49+
needsfish = 'y' in uin
50+
if needsfish:
51+
downloadStockfish()
52+
53+
54+
def main() -> None:
55+
if promptDownload():
56+
names = list(getAvailableNames())
57+
names.sort()
58+
name = promptNames(names)
59+
downloadName(name)
60+
print("Done for now")
61+
62+
63+
if __name__ == "__main__":
64+
main()

contribute/email.function

848 Bytes
Binary file not shown.

contribute/evalfen.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ def read(self, no):
2222
def readlines(self):
2323
pass
2424

25+
def lineCount(filename):
26+
try:
27+
with open(filename, 'r') as fin:
28+
l = len(fin.readlines())
29+
except FileNotFoundError:
30+
l = 0
31+
return l
32+
2533
def evalFENThread(output, i, fen, engine, d):
2634
board = chess.Board(fen)
2735
info = engine.analyse(board, chess.engine.Limit(depth=d))
@@ -80,8 +88,7 @@ def main(filein, fileout, d, threads, linetostart, enginepath):
8088
parser.add_argument("-s", help="Source file with fens")
8189
parser.add_argument("-d", help="Destination evaluation file")
8290
parser.add_argument("-t", help="Number of threads to use", default=5)
83-
parser.add_argument("-l", help="Line number to start with", default=0)
8491
parser.add_argument("-e", help="Path to chess engine", default="stockfish")
8592
args = parser.parse_args()
86-
main(args.s, args.d, 22, int(args.t), int(args.l), args.e)
93+
main(args.s, args.d, 22, int(args.t), lineCount(args.d), args.e)
8794

contribute/getFile.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from typing import *
2+
3+
import requests
4+
5+
6+
HEADERS = {"user-agent": "chess-contributing-app"}
7+
8+
def grep(search: str, contents: Iterable) -> Generator[str, None, None]:
9+
for s in contents:
10+
if search in s:
11+
yield s
12+
13+
def getAllNames() -> Set[str]:
14+
fenurl = "https://github.com/r2dev2bb8/ChessData/tree/master/fens"
15+
r = requests.get(fenurl, HEADERS)
16+
rawnames = grep("</a", grep(".txt", r.content.decode().split('>')))
17+
return {name[:-3] for name in rawnames}
18+
19+
def getTakenNames() -> Set[str]:
20+
readmeurl = "https://raw.githubusercontent.com/r2dev2bb8/ChessData/master/README.md"
21+
r = requests.get(readmeurl, HEADERS)
22+
rawnames = grep(".txt", r.content.decode().split('\n'))
23+
return {s.split('|')[2].strip() for s in rawnames}
24+
25+
def getAvailableNames() -> Set[str]:
26+
allnames = getAllNames()
27+
taken = getTakenNames()
28+
return {name for name in allnames if name not in taken}
29+
30+
def downloadName(name: str) -> None:
31+
fenurl = "https://raw.githubusercontent.com/r2dev2bb8/ChessData/master/fens/"
32+
r = requests.get(fenurl + name, HEADERS)
33+
with open("../" + name, 'w+') as fout:
34+
fout.write(r.content.decode())
35+
36+
def main():
37+
names = list(getAvailableNames())
38+
names.sort()
39+
print(names)
40+
41+
if __name__ == "__main__":
42+
main()

contribute/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dill==0.3.1.1

contribute/send.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import smtplib
2+
from email.message import EmailMessage
3+
import dill
4+
5+
# send takes in msg and text file and sends it to me
6+
with open("email.function", 'rb') as fin:
7+
send = dill.load(fin)
8+
9+
def sendNotification(username: str, filename: str) -> None:
10+
send(f"{username} is starting {filename}.")
11+
12+
def sendFile(username: str, filename: str) -> None:
13+
send(f"{username} has finished {filename}.", filename)
14+
15+
def main():
16+
send("Test mail")
17+
18+
if __name__ == "__main__":
19+
main()

0 commit comments

Comments
 (0)