Created
June 27, 2020 19:27
-
-
Save caloni/1ac52ab61cef7d290537080f7ba38d28 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