Skip to content

Instantly share code, notes, and snippets.

@caloni
Created August 20, 2020 01:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caloni/4d5f81365a01ef9567d5d4e077403d70 to your computer and use it in GitHub Desktop.
Save caloni/4d5f81365a01ef9567d5d4e077403d70 to your computer and use it in GitHub Desktop.
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