summaryrefslogtreecommitdiff
path: root/pgn.py
diff options
context:
space:
mode:
authornea <nea@nea.moe>2023-03-12 00:25:33 +0100
committernea <nea@nea.moe>2023-03-12 00:25:33 +0100
commit56d31408bf14749a211ea87835f99bbb0ec1caf1 (patch)
treed0dfeb73b4e1ddb8a35ee9c57862889faa4bc908 /pgn.py
parent3236ef30b19e5e7a8a0e692b3c780fe5ca0786b1 (diff)
downloadchess-master.tar.gz
chess-master.tar.bz2
chess-master.zip
PGN exportHEADmaster
Diffstat (limited to 'pgn.py')
-rw-r--r--pgn.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/pgn.py b/pgn.py
new file mode 100644
index 0000000..ee9489b
--- /dev/null
+++ b/pgn.py
@@ -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)
+
+