diff options
author | nea <nea@nea.moe> | 2023-03-12 00:25:33 +0100 |
---|---|---|
committer | nea <nea@nea.moe> | 2023-03-12 00:25:33 +0100 |
commit | 56d31408bf14749a211ea87835f99bbb0ec1caf1 (patch) | |
tree | d0dfeb73b4e1ddb8a35ee9c57862889faa4bc908 /pgn.py | |
parent | 3236ef30b19e5e7a8a0e692b3c780fe5ca0786b1 (diff) | |
download | chess-56d31408bf14749a211ea87835f99bbb0ec1caf1.tar.gz chess-56d31408bf14749a211ea87835f99bbb0ec1caf1.tar.bz2 chess-56d31408bf14749a211ea87835f99bbb0ec1caf1.zip |
Diffstat (limited to 'pgn.py')
-rw-r--r-- | pgn.py | 36 |
1 files changed, 36 insertions, 0 deletions
@@ -0,0 +1,36 @@ +import datetime +import json + + +class PgnWriter: + + def __init__(self): + self.pgn_string = "" + + def visit_tag(self, label: str, value: str): + self.pgn_string += "[" + label + " " + json.dumps(str(value)) + "]" + + def visit_event(self, event_name: str): + self.visit_tag("Event", event_name) + + def visit_site(self, site: str): + self.visit_tag("Site", site) + + def visit_start_time(self, date: datetime.datetime): + self.visit_tag("Date", date.strftime('%Y.%m.%d')) + self.visit_tag("Time", date.strftime('%H:%M:%S')) + + def visit_is_online(self, is_online: bool): + self.visit_tag("Mode", "ICS" if is_online else "OTB") + + def visit_fen(self, fen: str): + self.visit_tag("FEN", fen) + + def visit_round(self, round: int | str): + self.visit_tag("Round", str(round)) + + def visit_players(self, white: str, black: str): + self.visit_tag("White", white) + self.visit_tag("Black", black) + + |