From a0d76f32ec2067b7d185104cdcf877342d29f73e Mon Sep 17 00:00:00 2001 From: andrew Date: Tue, 19 Mar 2024 23:19:16 -0400 Subject: [PATCH] Turn an archive into a single pgn file, via stdout --- Scripts/archive2pgns.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Scripts/archive2pgns.py diff --git a/Scripts/archive2pgns.py b/Scripts/archive2pgns.py new file mode 100644 index 0000000..30c68d3 --- /dev/null +++ b/Scripts/archive2pgns.py @@ -0,0 +1,38 @@ +#!/bin/python3 + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# # +# OpenBench is a chess engine testing framework by Andrew Grant. # +# # +# # +# OpenBench is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# OpenBench is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # + +import argparse +import bz2 +import tarfile + +if __name__ == '__main__': + + parser = argparse.ArgumentParser() + parser.add_argument('archive', help='Path to the OpenBench pgn archive') + args = parser.parse_args() + + data = {} + with tarfile.open(args.archive, 'r') as tar: + for member in filter(lambda x: x.isfile(), tar.getmembers()): + if file := tar.extractfile(member): + for line in bz2.decompress(file.read()).decode('utf-8').split('\n'): + print (line) \ No newline at end of file