Run code from GitHub

Hello, thats problably a really dumb/easy question, but:
I need a program wich converts a pgn into fen.
First, I thought about writing some code with the python-chess libary, but then I found a github project, that does what I need: GitHub - SindreSvendby/pgnToFen: Takes PGN as input and returns FEN
The problem is, I don’t know wich code I have to run, because the only code that works is pgntofen.py, which gives me 27 FEN’s, which are problably one game. But I didn’t find the input in the code, so I’m not able to change it :frowning:
Do you know how to run this code, or is there any other program/code (with python chess)?

In the end, I want to get many FEN’s and with these I wantet to analyze them with an engine to get the best move for this FEN.
e.g: rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1 best Move: ‘d4’

I tought of using this project for the second step: GitHub - fsmosca/chess-artist: A python script that can annotate chess games in pgn file with static evaluation or search score of an engine, can annotate an epd file with acd, acs, bm, and ce opcodes, can test engine with epd test suite and can generate chess puzzles.
Does anyone knows if this is possible, or even better, without ever converting it to FEN?

Thank you for your answers!

The README in the repo seems to cover usage and examples.

Specifically it sounds like you’d be interested in this part: pgnFile

Yes, that’s exactly what I want.
But how do I execute this? I’m a noob, so please explain it to me in a way that I can understand :smile:

The sample there is Python code, you need to put the code (possibly adjusted to your needs) into a file and run it with the Python interpreter. Looking at the Python tutorial is a good place to start for working with Python.

Hello
Yes, I tried this to and used the exact same code as in the example, but I got the error pgntofen not found, even it is in the same folder…

Can you show us the exact code and commands you are using? Without that it’s very hard to guess what might be wrong.

So, basically I‘m just using this code, to run the program with the testfile: pgnConverter = pgntofen.PgnToFen()
pgnConverter.resetBoard()
file = “test/Carlsen.pgn”
stats = pgnConverter.pgnFile(file);

The error that occurs is „pgntofen“ not found. I will send some pictures as soon as I get home.

Thanks for your answers!

If it’s literally just that snippet and the pgntofen.py module file is in the same directory, you probably just need to import the module before using it:

import pgntofen
pgnConverter = pgntofen.PgnToFen()

Thats a good idea, but it didn’t work. I get a output of the games, but not in FEN. Instead i got something like this:

‘e4’, ‘c5’, ‘Nf3’, ‘d6’, ‘d4’, ‘cxd4’, ‘Nxd4’, ‘Nf6’, ‘Nc3’, ‘g6’, ‘Be2’, ‘Bg7’, ‘O-O’, ‘O-O’, ‘Re1’, ‘Nc6’, ‘Nb3’, ‘Be6’, ‘Bf1’, ‘Rc8’, ‘Nd5’, ‘a6’, ‘c3’, ‘Nd7’, ‘Bg5’, ‘h6’, ‘Be3’, ‘Nce5’, ‘Qd2’, ‘Kh7’, ‘Bd4’, ‘b5’, ‘f4’, ‘Nc4’, ‘Qf2’, ‘Bxd5’, ‘exd5’, ‘Nf6’, ‘Rad1’, ‘a5’, ‘h3’, ‘a4’, ‘Na1’, ‘a3’, ‘Bxc4’, ‘bxc4’, ‘bxa3’, ‘Qa5’, ‘Nc2’, ‘Rfe8’, ‘Nb4’, ‘Qxa3’, ‘Re3’, ‘Qa5’, ‘Qe2’, ‘Nxd5’, ‘Nxd5’, ‘e5’, ‘Bb6’, ‘Qb5’, ‘fxe5’, ‘dxe5’, ‘Rf3’, ‘f5’, ‘Rff1’, ‘Qc6’, ‘Bf2’, ‘e4’, ‘Nb4’, ‘Qe6’, ‘Bd4’, ‘Red8’, ‘Qe3’, ‘Bxd4’, ‘Rxd4’, ‘Rxd4’, ‘Qxd4’, ‘Re8’, ‘Nd5’, ‘Re7’, ‘Nxe7’