Created
August 20, 2020 01:43
-
-
Save caloni/4d5f81365a01ef9567d5d4e077403d70 to your computer and use it in GitHub Desktop.
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
import chess.pgn | |
import io | |
import sys | |
import urllib.request | |
def getpgn(path): | |
if path.find("http") == 0: | |
response = urllib.request.urlopen(path) | |
data = response.read() | |
text = data.decode('utf-8') | |
return io.StringIO(text) | |
else: | |
return open(path) | |
def printpgn(pgn): | |
game = chess.pgn.read_game(pgn) | |
while game: | |
board = game.board() | |
print(game, '\n') | |
print(board, '\n') | |
for move in game.mainline_moves(): | |
board.push(move) | |
print(move, '\n') | |
print(board, '\n') | |
game = chess.pgn.read_game(pgn) | |
for arg in sys.argv[1:]: | |
pgn = getpgn(arg) | |
printpgn(pgn) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment