Skip to content

Commit

Permalink
Add opening counter and tourmente downloads
Browse files Browse the repository at this point in the history
  • Loading branch information
vitogit committed Nov 1, 2019
1 parent 0279b9d commit 7113e9a
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 1 deletion.
2 changes: 1 addition & 1 deletion download_games.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

logging.debug("Downloading games from: "+settings.username)

response = requests.get('https://lichess.org/api/games/user/'+settings.username+'?max='+settings.max+'&token=' + settings.token+'&perfType=blitz,rapid,classical')
response = requests.get('https://lichess.org/api/games/user/'+settings.username+'?max='+settings.max+'&token=' + settings.token+'&perfType=blitz,rapid,classical&opening=true')
pgn = str(response.text)
all_games = open("games.pgn", "w")
all_games.write(pgn)
Expand Down
36 changes: 36 additions & 0 deletions download_tourments.py
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 ")
53 changes: 53 additions & 0 deletions opening_counter.py
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))

0 comments on commit 7113e9a

Please sign in to comment.