-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add opening counter and tourmente downloads
- Loading branch information
Showing
3 changed files
with
90 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/usr/bin/env python | ||
|
||
"""Downloading chess puzzles for lichess.org""" | ||
|
||
import argparse | ||
import chess | ||
import chess.pgn | ||
import logging | ||
import os | ||
import sys | ||
import requests | ||
import chess | ||
import re | ||
import time | ||
|
||
|
||
# tourments | ||
tourment_ids = ['25MtoToy', | ||
'E14kHVwX', | ||
'tdntXNhy', | ||
'sj5GoEdS', | ||
'C4zdQLax', | ||
'wobqi6QP', | ||
'T4RW1ux2', | ||
'nzw7OKBq'] | ||
|
||
all_games = open("games.pgn", "w") | ||
pgn = "" | ||
for id in tourment_ids: | ||
print ('https://lichess.org/api/tournament/'+id+'/games') | ||
response = requests.get('https://lichess.org/api/tournament/'+id+'/games') | ||
pgn = pgn +'\n'+ str(response.text) | ||
|
||
all_games.write(pgn) | ||
all_games.close() | ||
logging.debug("Finished. Pgn is in games.pgn ") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/usr/bin/env python | ||
|
||
"""Creating chess puzzles for lichess.org""" | ||
import collections | ||
import argparse | ||
import chess | ||
import chess.uci | ||
import chess.pgn | ||
import logging | ||
import os | ||
import sys | ||
from modules.fishnet.fishnet import stockfish_command | ||
from modules.puzzle.puzzle import puzzle | ||
from modules.bcolors.bcolors import bcolors | ||
from modules.investigate.investigate import investigate | ||
from modules.api.api import post_puzzle | ||
|
||
parser = argparse.ArgumentParser(description=__doc__) | ||
|
||
parser.add_argument("threads", metavar="THREADS", nargs="?", type=int, default=4, | ||
help="number of engine threads") | ||
parser.add_argument("memory", metavar="MEMORY", nargs="?", type=int, default=2048, | ||
help="memory in MB to use for engine hashtables") | ||
parser.add_argument("--depth", metavar="DEPTH", nargs="?", type=int, default=8, | ||
help="depth for stockfish analysis") | ||
parser.add_argument("--quiet", dest="loglevel", | ||
default=logging.DEBUG, action="store_const", const=logging.INFO, | ||
help="substantially reduce the number of logged messages") | ||
parser.add_argument("--games", metavar="GAMES", default="games.pgn", | ||
help="A specific pgn with games") | ||
parser.add_argument("--strict", metavar="STRICT", default=True, | ||
help="If False then it will be generate more tactics but maybe a little ambiguous") | ||
settings = parser.parse_args() | ||
|
||
all_games = open(settings.games, "r") | ||
ecos_white = [] | ||
ecos_black = [] | ||
game_id = 0 | ||
while True: | ||
game = chess.pgn.read_game(all_games) | ||
if game == None: | ||
break | ||
if (game.headers["White"] == "engendrio"): | ||
ecos_white.append(game.headers["ECO"]+'-'+game.headers["Opening"]) | ||
else: | ||
ecos_black.append(game.headers["ECO"]+'-'+game.headers["Opening"]) | ||
|
||
print("WHITE_____") | ||
print(collections.Counter(ecos_white)) | ||
|
||
print() | ||
print("BLACK_____") | ||
print(collections.Counter(ecos_black)) |